Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New serverless pattern - API GW to SQS to Lambda to DDB #1480

Merged
merged 5 commits into from
Jul 24, 2023
Merged

New serverless pattern - API GW to SQS to Lambda to DDB #1480

merged 5 commits into from
Jul 24, 2023

Conversation

ravikirang28
Copy link

Description of changes: This pattern explains how to deploy a SAM application with Amazon API Gateway, Amazon SQS, AWS Lambda, and Amazon DynamoDB. When an HTTP POST request is made to the Amazon API Gateway endpoint, Gateway authorizes the request by checking Basic auth credentials and on valid credentials, request payload is sent to Amazon Simple Queue Service. AWS Lambda function consumes event from the Queue and inserts the event/payload into the Amazon DynamoDB table. Amazon Simple Queue Service is also configured with a Dead Letter Queue where events are sent when retries to process those messages are repeatedly failed. Diagram and more details are also documented in README file.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jbesw
Copy link
Contributor

jbesw commented Jul 7, 2023

This is missing the example-pattern.json metadata file. Please add so the pattern can be tested.

@ravikirang28
Copy link
Author

Missing example-pattern.json file is added now.

@ravikirang28
Copy link
Author

@mavi888 Please let me know for any questions or outstanding things to be addressed before this can be merged.


This pattern explains how to deploy a SAM application with Amazon API Gateway, Amazon SQS, AWS Lambda, and Amazon DynamoDB. When an HTTP POST request is made to the Amazon API Gateway endpoint, Gateway authorizes the request by checking Basic auth credentials and on valid credentials, request payload is sent to Amazon Simple Queue Service. AWS Lambda function consumes event from the Queue and inserts the event/payload into the Amazon DynamoDB table. Amazon Simple Queue Service is also configured with a Dead Letter Queue where events are sent when retries to process those messages are repeatedly failed.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a great pattern and very useful, so i think it would be good to mention in the intro of this pattern why is useful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded the intro section along with some key benefits

This pattern was contributed by Ravi Kiran Ganji.

----
Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update 2023

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


1. Delete the stack
```bash
aws cloudformation delete-stack --stack-name STACK_NAME
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sam delete

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Once the application is deployed:
- Retrieve the HttpApiEndpoint value from CloudFormation Outputs
- Retrieve the username and password from Secrets Manager in AWS Console.
- Invoke the endpoint from Postman using some json payload and verify the payload saved in DynamoDB.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make the command with curl, so its easier to copypaste in the cli

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Once the application is deployed:
- Retrieve the HttpApiEndpoint value from CloudFormation Outputs
- Retrieve the username and password from Secrets Manager in AWS Console.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secret manager should be mentioned before as it was not presented earlier.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Secrets manager is added to intro section

Example POST Request: https://{HttpApiEndpoint}.execute-api.us-east-1.amazonaws.com/submit
- Request Header: "Content-Type: application/json"
- Request Header: "Authorization: Basic <credentials>" (where credentials is the Base64 encoding of ID and password joined by a single colon :)
- Request Body: {"eventId":"value1", "message":"event message for testing"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should we see after we run this? What kind of information people testing this should look for?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded the whole testing section to add more details

aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"
```

This pattern was contributed by Ravi Kiran Ganji.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed as we do the attribution differently

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

- Messages from SQS is posted to a lambda function to process them.
- Lambda function receives the messages from SQS and saves them into a DynamoDB table.

## Testing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you add the DLQ it would be great to have an example on how to test that that is working.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a section to test DLQ

@mavi888
Copy link
Contributor

mavi888 commented Jul 18, 2023

This is a great pattern and very useful, that is why i would love to see a better readme. Please address the comments and I will merge this PR
Thanks for your contribution

@ravikirang28
Copy link
Author

@mavi888 Appreciate the feedback. I have updated the readme to address your feedback. Please take a look and let me know for any further comments.

@mavi888 mavi888 merged commit 2950847 into aws-samples:main Jul 24, 2023
@mavi888
Copy link
Contributor

mavi888 commented Jul 24, 2023

Thanks for submitting this pattern.
Now this is merged and you can see it here: https://serverlessland.com/patterns/apigw-sqs-lambda-ddb

@ravikirang28 ravikirang28 deleted the ravikirang28-feature-apigw-sqs-lambda-ddb branch July 24, 2023 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants