|
1 | 1 | # 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. |
3 | 3 |
|
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` |
7 | 8 | - 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 | +``` |
10 | 24 |
|
11 | 25 | The Scorekeep API integration is implemented in the following files- |
12 | 26 | `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. |
18 | 35 |
|
19 | 36 | # Scorekeep |
20 | 37 | 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