|
| 1 | +# AWS Kinesis Data Streams to AWS Lambda |
| 2 | + |
| 3 | +This pattern creates an AWS Kinesis Data Stream, a stream consumer, and an AWS Lambda function. When data is added to the stream, the Lambda function is invoked. |
| 4 | + |
| 5 | +Learn more about this pattern at Serverless Land Patterns: [https://serverlessland.com/patterns/kinesis-to-lambda-terraform](https://serverlessland.com/patterns/kinesis-to-lambda-terraform) |
| 6 | + |
| 7 | +Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. |
| 8 | + |
| 9 | +## Requirements |
| 10 | + |
| 11 | +* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources. |
| 12 | +* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured |
| 13 | +* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) |
| 14 | +* [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) installed |
| 15 | + |
| 16 | +## Deployment Instructions |
| 17 | + |
| 18 | +1. Clone the project to your local working directory |
| 19 | + |
| 20 | + ```sh |
| 21 | + git clone https://github.com/aws-samples/serverless-patterns/ |
| 22 | + ``` |
| 23 | + |
| 24 | +2. Change the working directory to this pattern's directory |
| 25 | + |
| 26 | + ```sh |
| 27 | + cd serverless-patterns/kinesis-lambda-terraform |
| 28 | + ``` |
| 29 | + |
| 30 | +1. From the command line, initialize terraform to to downloads and installs the providers defined in the configuration: |
| 31 | + ``` |
| 32 | + terraform init |
| 33 | + ``` |
| 34 | +1. From the command line, apply the configuration in the main.tf file: |
| 35 | + ``` |
| 36 | + terraform apply |
| 37 | + ``` |
| 38 | +1. During the prompts: |
| 39 | +
|
| 40 | + - Enter yes |
| 41 | +
|
| 42 | +## Testing |
| 43 | +
|
| 44 | +Use the Amazon Kinesis Data Generator for testing. The easiest way to use this tool is to use the [hosted generator](https://awslabs.github.io/amazon-kinesis-data-generator/web/producer.html) and follow the [setup instructions](https://awslabs.github.io/amazon-kinesis-data-generator/web/help.html). |
| 45 | +
|
| 46 | +After you have the generator configured, you should have a custom URL to generate data for your Kinesis data stream. In your configuration steps, you created a username and password. Log in to the generator using those credentials. |
| 47 | +
|
| 48 | +When you are logged in, you can generate data for your stream test. |
| 49 | +
|
| 50 | +1. Choose the region you deployed the application to |
| 51 | +2. For Stream/delivery stream, select your stream. |
| 52 | +3. For Records per second, keep the default value of 100. |
| 53 | +4. On the Template 1 tab, name the template Sensor1. |
| 54 | +5. Use the following template: |
| 55 | + ```JSON |
| 56 | + { |
| 57 | + "sensorId": {{random.number(50)}}, |
| 58 | + "currentTemperature": {{random.number( |
| 59 | + { |
| 60 | + "min":10, |
| 61 | + "max":150 |
| 62 | + } |
| 63 | + )}}, |
| 64 | + "status": "{{random.arrayElement( |
| 65 | + ["OK","FAIL","WARN"] |
| 66 | + )}}" |
| 67 | + } |
| 68 | + ``` |
| 69 | +6. Choose Send Data. |
| 70 | +7. After several seconds, choose Stop Sending Data. |
| 71 | +
|
| 72 | +## Cleanup |
| 73 | +
|
| 74 | +1. Delete all created resources by terraform |
| 75 | + ```bash |
| 76 | + terraform destroy |
| 77 | + ``` |
| 78 | +2. During the prompts: |
| 79 | + * Enter yes |
| 80 | +3. Confirm all created resources has been deleted |
| 81 | + ```bash |
| 82 | + terraform show |
| 83 | + ``` |
| 84 | +
|
| 85 | +---- |
| 86 | +Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
0 commit comments