You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-22Lines changed: 24 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff 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.
3
3
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.
4
7
5
8
## 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:
7
12
-`_lambda/lambda-role.yml` - Template that defines the role
8
13
-`_lambda/create-lambda-role.sh` - Script to create the role
9
14
-`_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
10
18
11
-
Run the script to create the role:
19
+
Run the create scripts to create the roles and function:
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.
15
24
16
25
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:
17
26
- AWSLambdaFullAccess
@@ -20,19 +29,20 @@ Deploy this branch to your Elastic Beanstalk environment. No further configurati
20
29
If you don't have an environment, see below.
21
30
22
31
## 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`
28
37
- Environment variables:
29
38
- 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
32
41
33
-
The role named "scorekeep-lambda" has the following policies:
42
+
The role has the following policies:
34
43
- Managed policy - AWSLambdaBasicExecutionRole
35
-
- Managed policy - AmazonSNSFullAccess
44
+
- Managed policy - AmazonSQSFullAccess
45
+
- Managed policy - AmazonS3FullAccess
36
46
- Managed policy - AWSXrayWriteOnlyAccess (optional) for compatibility with the xray branch
37
47
- Trust policy -
38
48
@@ -49,14 +59,6 @@ The role named "scorekeep-lambda" has the following policies:
49
59
]
50
60
}
51
61
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
-
60
62
# Scorekeep
61
63
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