Skip to content

Commit 79a3b77

Browse files
committed
readme
1 parent f56272b commit 79a3b77

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

README.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
1-
# AWS X-Ray
2-
Documentation: [X-Ray SDK for Java Sample Application](http://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-sample.html)
3-
1+
# AWS X-Ray on Amazon EC2 Container Service
42
If you haven't used X-Ray with Scorekeep yet, try the [`xray-gettingstarted`](https://github.com/awslabs/eb-java-scorekeep/tree/xray-gettingstarted) branch first.
53

6-
This branch shows advanced instrumentation with the AWS X-Ray SDK and includes features from other branches. Deploy this branch to see additional trace data in the X-Ray console. Then, follow the instructions below to add an instrumented AWS Lambda function and PostgreSQL database to the application.
4+
This branch shows an instrumented version of Scorekeep that runs in Amazon ECS, a service that lets you run Docker containers on Amazon EC2 instances. For ease of deployment, it uses a CloudFormation template to create all of the secondary resources used by Scorekeep, and Elastic Beanstalk to create the ECS cluster and deploy the containers.
75

8-
## AWS Lambda Integration
9-
From branch: [`lambda`](https://github.com/awslabs/eb-java-scorekeep/tree/lambda)
6+
**Prerequisites**
7+
Install the following tools to create Docker images, upload them to ECR, and register task definitions with ECS.
8+
- Docker
9+
- AWS CLI v1.14.0+
10+
- EB CLI
11+
- AWS user with permission for IAM, DynamoDB, SNS, ECS, CloudWatch Logs, and ECR
1012

11-
In the [`UserFactory`](https://github.com/awslabs/eb-java-scorekeep/tree/xray/src/main/java/scorekeep/UserFactory.java) class, Scorekeep calls a Node.js AWS Lambda function to generate random usernames. If the call to Lambda fails, Scorekeep falls back on a public API to generate names.
13+
**To deploy this branch**
14+
1. Update `aws.env` in the root of the repo with your account ID and region.
15+
2. Create the CloudFormation stack by running **make stack** in the cloudformation directory. (If you already have a stack from the `ecs` or `fargate` branches, run **make update** instead.)
1216

13-
Run the script in the `_lambda` folder to create the AWS Lambda function that Scorekeep calls to generate random names:
14-
eb-java-scorekeep/_lambda$ ./create-random-name.sh
17+
cloudformation$ make stack
1518

16-
The script uses a CloudFormation template and the AWS CLI to create the function and its execution role:
17-
- `_lambda/random-name.yml` - Template that defines the role and function
18-
- `_lambda/create-random-name.sh` - Script to create the role and function
19-
- `_lambda/delete-random-name.sh` - Script to delete the role and function
19+
3. Build and publish the Docker containers for the API, frontend, and X-Ray daemon by running `make publish` in each folder.
2020

21-
If you don't have the AWS CLI, [install it](http://docs.aws.amazon.com/cli/latest/userguide/installing.html) or use the CloudFormation console to create a stack with the template.
21+
$ make publish
22+
scorekeep-frontend$ make publish
23+
xray-daemon$ make publish
2224

23-
Next, add Lambda permission to your instance profile ([aws-elasticbeanstalk-ec2-role](https://console.aws.amazon.com/iam/home#/roles/aws-elasticbeanstalk-ec2-role)) to let the environment update the Lambda function:
24-
- AWSLambdaFullAccess
25+
4. Generate the task definition by running the `generate-dockerrun` script.
2526

26-
Note: In the `lambda` branch, Scorekeep creates the Lambda function with a configuration file. In this branch, you create the function independently with the same template that creates the role. This lets the `xray` branch work even if the Lambda function and role have not been created, whereas in the `lambda` branch, the deployment fails if you haven't created the required role.
27+
task-definition$ ./generate-dockerrun
2728

28-
Finally, redeploy this branch to your environment. During deployment, the [update script in `lambda-function.config`](https://github.com/awslabs/eb-java-scorekeep/blob/xray/.ebextensions/lambda-function.config#L31) builds the function and uploads the source code to Lambda.
29+
5. Initialize an Elastic Beanstalk repo in the task-definition folder. If you have an SSH key, you can specify it with the -k option.
2930

30-
Create a new user in the web app and refresh your service map to see the two Lambda nodes.
31+
task-definition$ eb init -p multi-container-docker -r us-east-1 scorekeep-ecs
3132

32-
## Amazon RDS Integration
33-
From branch: [`sql`](https://github.com/awslabs/eb-java-scorekeep/tree/sql)
34-
Documentation: [Instrumenting Calls to a PostgreSQL Database](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-java-sample.html#xray-sdk-java-sample-postgresql)
33+
6. Create a Multicontainer Docker environment.
3534

36-
In [`application-pgsql.properties`](https://github.com/awslabs/eb-java-scorekeep/tree/xray/src/main/resources/application-pgsql.properties), Scorekeep adds the X-Ray SDK tracing interceptor to the JDBC data source used by Hibernate.
35+
task-definition$ eb create -d -i m5.large --sample --instance_profile scorekeep-beanstalk-ecs-role scorekeep
3736

38-
[Add a PostgreSQL database](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.managing.db.html) to your Elastic Beanstalk environment to enable SQL tracing on the X-Ray demo page (/#/xray).
37+
7. Deploy the task definition.
3938

40-
Hibernate also calls the database during application startup. No segment is available to the X-Ray SDK during startup, so we create one manually in [`RdsWebConfig.java`](https://github.com/awslabs/eb-java-scorekeep/blob/xray/src/main/java/scorekeep/RdsWebConfig.java#L83) by overriding Hibernate's `SchemaExport` class.
39+
task-definition$ eb deploy
4140

4241
# Scorekeep
4342
Scorekeep is a RESTful web API implemented in Java that uses Spring to provide an HTTP interface for creating and managing game sessions and users. This project includes the Scorekeep API and a front-end web app that consumes it. The front end and API can run on the same server and domain or separately, with the API running in Elastic Beanstalk and the front end served statically by a CDN.

0 commit comments

Comments
 (0)