Skip to content

Commit e44cb25

Browse files
committed
readme
1 parent e024ae1 commit e44cb25

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

README.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
# Lambda integration
2-
This branch uses a Node.js Lambda function to generate random names for new users, instead of calling a web API. The Scorekeep API uses the AWS SDK to invoke the Lambda by function name (`random-name`) with Bean classes to represent (and serialize to/from) the input and output JSON.
1+
# Lambda worker
2+
This branch adds a Lambda worker function, SQS queue, and CloudWatch Events to the contents of the `lambda` branch. The worker is a Python 3 function that processes game records and stores the output in S3. A CloudWatch Event fires every 5 minutes, triggering the Lambda function, which pulls the ID of a completed game from the SQS queue, reads all of the associated data from DynamoDB, and outputs a record of the game session in JSON format.
33

4+
To use this branch, first deploy the Lambda functions with the included shell scripts, described in the configuration section. See the `lambda` branch for details on the `random-name` function.
5+
6+
With this branch deployed, the worker function pulls game data out of multiple DynamoDB and stores it in single JSON files organized by date. You can perform queries on this data with Amazon Athena to do lightweight analytics with no servers-- no worker instance processing the data, and no database instance storing it.
47

58
## Configuration
6-
A CloudFormation template and [AWS CLI](http://docs.aws.amazon.com/cli/latest/userguide/installing.html) scripts to create and delete the function's execution role are included in the `_lambda` folder:
9+
Create the worker function with the `create-scorekeep-worker.sh` function in the `_lambda` folder
10+
11+
Use the CloudFormation templates and [AWS CLI](http://docs.aws.amazon.com/cli/latest/userguide/installing.html) scripts to create the required function and roles:
712
- `_lambda/lambda-role.yml` - Template that defines the role
813
- `_lambda/create-lambda-role.sh` - Script to create the role
914
- `_lambda/delete-lambda-role.sh` - Script to delete the role
15+
- `_lambda/scorekeep-worker.yml` - Template that defines the function
16+
- `_lambda/create-scorekeep-worker.sh` - Script to create the function
17+
- `_lambda/delete-scorekeep-worker.sh` - Script to delete the function
1018

11-
Run the script to create the role:
19+
Run the create scripts to create the roles and function:
1220
eb-java-scorekeep/_lambda$ ./create-lambda-role.sh
21+
eb-java-scorekeep/_lambda$ ./create-scorekeep-worker.sh
1322

14-
If you don't have the AWS CLI, use the CloudFormation console to create a stack with the template.
23+
If you don't have the AWS CLI, use the CloudFormation console to create a stack with the templates.
1524

1625
Next, add the following policy to your instance profile ([aws-elasticbeanstalk-ec2-role](https://console.aws.amazon.com/iam/home#/roles/aws-elasticbeanstalk-ec2-role)) to let the environment create the Lambda function:
1726
- AWSLambdaFullAccess
@@ -20,19 +29,20 @@ Deploy this branch to your Elastic Beanstalk environment. No further configurati
2029
If you don't have an environment, see below.
2130

2231
## Implementation
23-
The Lambda function code is included in `_lambda/random-name/index.js`. On deploy, configuration files in the .ebextensions folder create a function with the following settings:
24-
- Name: `random-name`
25-
- Runtime: Node.js 4.3
26-
- Description: `Generate random names`
27-
- Code: in `_Lambda/random-name`
32+
The Lambda function code is included in `_lambda/scorekeep-worker/worker.py`. On deploy, configuration files in the .ebextensions folder create a function with the following settings:
33+
- Name: `scorekeep-worker`
34+
- Runtime: Python3.6
35+
- Description: `Flatten game records for analytics`
36+
- Code: in `_Lambda/scorekeep-worker`
2837
- Environment variables:
2938
- REGION_NAME: The region, e.g. `us-east-2`
30-
- TOPIC_ARN: The ARN of an [SNS Topic](https://console.aws.amazon.com/sns/v2/home)
31-
- Role named "scorekeep-lambda"
39+
- WORKER_QUEUE: The URL of an SQS Queue
40+
- IAM role with permissions for the function
3241

33-
The role named "scorekeep-lambda" has the following policies:
42+
The role has the following policies:
3443
- Managed policy - AWSLambdaBasicExecutionRole
35-
- Managed policy - AmazonSNSFullAccess
44+
- Managed policy - AmazonSQSFullAccess
45+
- Managed policy - AmazonS3FullAccess
3646
- Managed policy - AWSXrayWriteOnlyAccess (optional) for compatibility with the xray branch
3747
- Trust policy -
3848

@@ -49,14 +59,6 @@ The role named "scorekeep-lambda" has the following policies:
4959
]
5060
}
5161

52-
The Scorekeep API integration is implemented in the following files-
53-
`src/main/java/scorekeep/`
54-
- `RandomNameInput.java` - Bean for the input, a user ID and category.
55-
- `RandomNameOutput.java` - Bean for the output, a first name.
56-
- `RandomNameService.java` - Defines the method used to call the Lambda function. Combined with an AWS SDK Lambda client to create a Lambda Invoker.
57-
- `UserFactory.java` - **UserFactory.randomNameLambda** Creates the Lambda Invoker with `com.amazonaws.services.lambda.invoke.LambdaInvokerFactory`. Calls the Lambda function to generate a random name.
58-
- `build.gradle` - Adds the Lambda module of the AWS SDK to the Gradle build.
59-
6062
# Scorekeep
6163
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.
6264

0 commit comments

Comments
 (0)