Skip to content

Commit 32cf2fd

Browse files
committed
instructions
1 parent 21a2793 commit 32cf2fd

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
# Lambda integration
2-
This branch uses a Node.js Lambda function to generate random names for new users.
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.
33

4-
The Lambda function code is included in `_lambda/random-name/index.js`.
5-
Create a Lambda function with this code and the following settings:
6-
- Name: random-name
4+
The Lambda function code is included in `_lambda/random-name/index.js`. Create a Lambda function with the following settings:
5+
- Template: blank function
6+
- Triggers: none
7+
- Name: `random-name`
78
- Runtime: Node.js 4.3
8-
- Environment variables: REGION_NAME and TOPIC_ARN
9-
- Include AWS SDK
9+
- Description: `Generate random names`
10+
- Code: in `_Lambda/random-name`
11+
- Run `npm install`
12+
- Run `zip -r ../random-name.zip *`
13+
- Upload the ZIP archive
14+
- Environment variables:
15+
- REGION_NAME: The region, e.g. `us-east-2`
16+
- TOPIC_ARN: The ARN of an [SNS Topic](https://console.aws.amazon.com/sns/v2/home)
17+
- Role with permission to call SNS
18+
- Test event:
19+
```
20+
{
21+
"userid": "1ABCDEFG"
22+
}
23+
```
1024

1125
The Scorekeep API integration is implemented in the following files-
1226
`src/main/java/scorekeep/`
13-
- RandomNameInput.java
14-
- RandomNameOutput.java
15-
- RandomNameService.java
16-
- UserFactory.java
17-
- build.java
27+
- `RandomNameInput.java` - Bean for the input, a user ID and category.
28+
- `RandomNameOutput.java` - Bean for the output, a first name.
29+
- `RandomNameService.java` - Defines the method used to call the Lambda function. Combined with an AWS SDK Lambda client to create a Lambda Invoker.
30+
- `UserFactory.java` - **UserFactory.randomNameLambda** Creates the Lambda Invoker with `com.amazonaws.services.lambda.invoke.LambdaInvokerFactory`. Calls the Lambda function to generate a random name.
31+
- `build.gradle` - Adds the Lambda module of the AWS SDK to the Gradle build.
32+
33+
Deploy this branch to your Elastic Beanstalk environment. No further configuration is required.
34+
If you don't have an environment, see below.
1835

1936
# Scorekeep
2037
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.

_lambda/random-name/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
"url": "eb-java-scorekeep"
1212
},
1313
"author": "mwunderl",
14-
"license": "Apache-2.0"
14+
"license": "Apache-2.0",
15+
"dependencies": {
16+
"chance": "^1.0.4"
17+
}
1518
}

0 commit comments

Comments
 (0)