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
+39-11Lines changed: 39 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,25 @@
1
1
# Lambda integration
2
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.
3
3
4
+
5
+
## 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:
7
+
-`_lambda/lambda-role.yml` - Template that defines the role
8
+
-`_lambda/create-lambda-role.sh` - Script to create the role
9
+
-`_lambda/delete-lambda-role.sh` - Script to delete the role
If you don't have the AWS CLI, use the CloudFormation console to create a stack with the template.
15
+
16
+
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
+
- AWSLambdaFullAccess
18
+
19
+
Deploy this branch to your Elastic Beanstalk environment. No further configuration is required.
20
+
If you don't have an environment, see below.
21
+
22
+
## Implementation
4
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:
5
24
- Name: `random-name`
6
25
- Runtime: Node.js 4.3
@@ -9,14 +28,26 @@ The Lambda function code is included in `_lambda/random-name/index.js`. On deplo
9
28
- Environment variables:
10
29
- REGION_NAME: The region, e.g. `us-east-2`
11
30
- TOPIC_ARN: The ARN of an [SNS Topic](https://console.aws.amazon.com/sns/v2/home)
12
-
- Role named "lambda-scorekeep"
13
-
14
-
Create a role named "lambda-scorekeep" in the IAM management console and add the following policies:
15
-
- AWSLambdaBasicExecutionRole
16
-
- AmazonSNSFullAccess
17
-
18
-
While you are there, add the following policy to your instance profile (aws-elasticbeanstalk-ec2-role) to let the environment create the Lambda function:
19
-
- AWSLambdaFullAccess
31
+
- Role named "scorekeep-lambda"
32
+
33
+
The role named "scorekeep-lambda" has the following policies:
34
+
- Managed policy - AWSLambdaBasicExecutionRole
35
+
- Managed policy - AmazonSNSFullAccess
36
+
- Managed policy - AWSXrayWriteOnlyAccess (optional) for compatibility with the xray branch
37
+
- Trust policy -
38
+
39
+
{
40
+
"Version": "2012-10-17",
41
+
"Statement": [
42
+
{
43
+
"Effect": "Allow",
44
+
"Principal": {
45
+
"Service": "lambda.amazonaws.com"
46
+
},
47
+
"Action": "sts:AssumeRole"
48
+
}
49
+
]
50
+
}
20
51
21
52
The Scorekeep API integration is implemented in the following files-
22
53
`src/main/java/scorekeep/`
@@ -26,9 +57,6 @@ The Scorekeep API integration is implemented in the following files-
26
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.
27
58
-`build.gradle` - Adds the Lambda module of the AWS SDK to the Gradle build.
28
59
29
-
Deploy this branch to your Elastic Beanstalk environment. No further configuration is required.
30
-
If you don't have an environment, see below.
31
-
32
60
# Scorekeep
33
61
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.
0 commit comments