Skip to content

Commit 5ec263e

Browse files
committed
Merge branch 'lambda' into xray
2 parents 195c9b2 + 2b8fda2 commit 5ec263e

File tree

5 files changed

+74
-16
lines changed

5 files changed

+74
-16
lines changed

README.md

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ In [`application-pgsql.properties`](https://github.com/awslabs/eb-java-scorekeep
3636
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.
3737

3838
# Scorekeep
39-
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 frontend web app that consumes it. The frontend and API can run on the same server and domain or separately, with the API running in Elastic Beanstalk and the frontend served statically by a CDN.
39+
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 frontend web app that consumes it. The frontend and API can run on the same server and domain or separately, with the API running in Elastic Beanstalk and the frontend served statically by a CDN.
4040

41-
The project shows the use of Spring, Angular, nginx, the AWS SDK for Java, DynamoDB, Gradle, CORS, and Elastic Beanstalk features that let you run both components on the same EC2 instance, create required DynamoDB tables as part of the Elastic Beanstalk environment, and build the API from source on-instance during deployment.
41+
The `master` branch shows the use of Spring, Angular, nginx, the AWS SDK for Java, DynamoDB, Gradle, CORS, and Elastic Beanstalk features that let you run both components on the same EC2 instance, create required DynamoDB and SNS resources as part of the Elastic Beanstalk environment, and build the API from source on-instance during deployment.
42+
43+
Other branches extend the application's functionality and show the use of other AWS services. See the readme in each branch for details about the integration, and instructions for use.
4244

4345
**Branches**
4446
- [`cognito`](https://github.com/awslabs/eb-java-scorekeep/tree/cognito) - Support login and store users in a Cognito user pool.
@@ -47,9 +49,35 @@ The project shows the use of Spring, Angular, nginx, the AWS SDK for Java, Dynam
4749
- [`xray`](https://github.com/awslabs/eb-java-scorekeep/tree/xray) - Use the AWS X-Ray SDK to instrument incoming requests, SDK clients, SQL queries, HTTP clients, and sections of code.
4850
- [`xray-gettingstarted`](https://github.com/awslabs/eb-java-scorekeep/tree/xray-gettingstarted) ([tutorial](https://docs.aws.amazon.com/xray/latest/devguide/xray-gettingstarted.html)) - Use the AWS X-Ray to instrument incoming requests and SDK clients (no additional configuration required).
4951

50-
Use the procedures in the following sections to run the project on AWS Elastic Beanstalk and configure it for local testing and development.
52+
Use the procedures in the following sections to run the project on AWS Elastic Beanstalk and configure it for local testing and development.
53+
54+
**Sections**
55+
- [Prerequisites](#prerequisites)
56+
- [Deploy the application](#deploy-the-application)
57+
- [Configure notifications](#configure-notifications)
58+
- [How it works](#how-it-works)
59+
- [Running the project locally](#running-the-project-locally)
60+
- [Contributing](#contributing)
61+
62+
# Prerequisites
63+
- User permissions - Elastic Beanstalk, IAM*
64+
- Instance profile with permission to use DynamoDB and SNS
65+
- Elastic Beanstalk environment running Java 8
66+
67+
*If you don't have permission to manage permissions in IAM, get someone who does to add DynamoDB and SNS permissions to the default Elastic Beanstalk instance profile.
68+
69+
## Get permission to use Elastic Beanstalk
70+
If you are using an IAM user with limited permissions, good work! Add Elastic Beanstalk permissions to your user account to get started.
71+
72+
*To add Elastic Beanstalk permissions to an IAM user*
73+
74+
1. Sign in to a user or role with administrator permissions.
75+
2. Open the [users page](https://console.aws.amazon.com/iam/home#/users) of the IAM console.
76+
3. Choose a user.
77+
4. Click **Add permissions**.
78+
5. Add the **AWSElasticBeanstalkFullAccess** managed policy.
5179

52-
## Create an AWS Elastic Beanstalk environment
80+
## Create an Elastic Beanstalk environment
5381
Create a Java 8 SE environment in Elastic Beanstalk to host the application.
5482

5583
*To create an Elastic Beanstalk environment running the Java 8 SE platform*
@@ -69,7 +97,7 @@ When the Scorekeep API runs in AWS Elastic Beanstalk, it uses the permissions of
6997
3. Select [AmazonDynamoDBFullAccess](https://console.aws.amazon.com/iam/home#policies/arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess) and click **Attach Policy**.
7098
3. Select [AmazonSNSFullAccess](https://console.aws.amazon.com/iam/home#policies/arn:aws:iam::aws:policy/AmazonSNSFullAccess) and click **Attach Policy**.
7199

72-
## Deploy the application
100+
# Deploy the application
73101
Deploy the source code for the project to your Elastic Beanstalk environment.
74102

75103
*To deploy the source code*
@@ -85,7 +113,7 @@ Deploy the source code for the project to your Elastic Beanstalk environment.
85113

86114
Click through the app to explore its functionality. Use the network console in your browser to see the HTTP requests that it sends to the API to read and write users, sessions, games, moves and game state to DynamoDB via the API.
87115

88-
## Configure Notifications
116+
# Configure notifications
89117
The API uses Amazon SNS to send a notification email when a game ends. To enable notifications, configure your email address in an environment variable.
90118

91119
*To enable notifications*
@@ -195,4 +223,30 @@ When you run both the API and frontend in the same Elastic Beanstalk environment
195223

196224
~/eb-java-scorekeep$ git archive -o scorekeep-v1.zip HEAD
197225

198-
5. Open your environment's Dashboard in the [Elastic Beanstalk Management Console](console.aws.amazon.com/elasticbeanstalk/home) and deploy the updated code.
226+
5. Open your environment's Dashboard in the [Elastic Beanstalk Management Console](console.aws.amazon.com/elasticbeanstalk/home) and deploy the updated code.
227+
228+
# Contributing
229+
230+
This sample application could be better with your help!
231+
232+
- Add a new game!
233+
- Implement game logic in game class. See [TicTacToe.java](https://github.com/awslabs/eb-java-scorekeep/blob/master/src/main/java/scorekeep/TicTacToe.java)
234+
- Add the class to [RulesFactory.java](https://github.com/awslabs/eb-java-scorekeep/blob/master/src/main/java/scorekeep/RulesFactory.java)
235+
- Create your own client frontend!
236+
- Web frameworks - Angular 2, React, ember, etc
237+
- Mobile app
238+
- Desktop application
239+
- Integrate with other AWS services!
240+
- CICD with CodeCommit, CodePipeline, CodeBuild, and CodeDeploy
241+
- Analytics with Kinesis, Athena, EMR, or QuickSight
242+
- Security with VPC
243+
- Performance with ElastiCache
244+
- Scalability with CloudFront
245+
- Portability with ECS or CloudFormation
246+
- Accessibility with Polly
247+
- Write tests!
248+
- Unit tests
249+
- Integration tests
250+
- Functional tests
251+
- Load tests
252+
- File an [issue](https://github.com/awslabs/eb-java-scorekeep/issues) to report a bug or request new features.

src/main/java/scorekeep/GameModel.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
77
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression;
88
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
9-
import com.amazonaws.xray.AWSXRay;
10-
import com.amazonaws.xray.entities.Segment;
11-
import com.amazonaws.xray.entities.Subsegment;
12-
import com.amazonaws.xray.handlers.TracingHandler;
139

1410
import java.util.HashMap;
1511
import java.util.List;
1612
import java.util.Map;
1713
import java.util.Set;
1814

15+
import com.amazonaws.xray.AWSXRay;
16+
import com.amazonaws.xray.entities.Segment;
17+
import com.amazonaws.xray.entities.Subsegment;
18+
import com.amazonaws.xray.handlers.TracingHandler;
19+
1920
public class GameModel {
2021
/** AWS SDK credentials. */
2122
private AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()

src/main/java/scorekeep/SessionModel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
66
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
77
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
8+
9+
import java.util.List;
10+
811
import com.amazonaws.xray.AWSXRay;
912
import com.amazonaws.xray.entities.Subsegment;
1013
import com.amazonaws.xray.handlers.TracingHandler;
1114

12-
import java.util.List;
13-
1415
public class SessionModel {
1516
/** AWS SDK credentials. */
1617
private AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()

src/main/java/scorekeep/UserFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package scorekeep;
22

3-
import com.amazonaws.xray.proxies.apache.http.HttpClientBuilder;
43
import com.fasterxml.jackson.databind.ObjectMapper;
54
import org.apache.http.HttpEntity;
65
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -22,6 +21,8 @@
2221
import com.amazonaws.regions.Regions;
2322
import com.amazonaws.services.lambda.model.ResourceNotFoundException;
2423

24+
import com.amazonaws.xray.proxies.apache.http.HttpClientBuilder;
25+
2526
public class UserFactory {
2627
private SecureRandom random = new SecureRandom();
2728
private UserModel model = new UserModel();

src/main/java/scorekeep/UserModel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
66
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
77
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
8+
9+
import java.util.List;
10+
811
import com.amazonaws.xray.AWSXRay;
912
import com.amazonaws.xray.entities.Subsegment;
1013
import com.amazonaws.xray.handlers.TracingHandler;
1114

12-
import java.util.List;
13-
1415
public class UserModel {
1516
/** AWS SDK credentials. */
1617
private AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()

0 commit comments

Comments
 (0)