Skip to content

Conversation

enmata
Copy link

@enmata enmata commented Jul 8, 2024

Issue #, if available:
Adding s3-sqs-lambda-terraform pattern

Description of changes:
Adding the terraform version of Add s3-sqs-lambda pattern
https://serverlessland.com/patterns/s3-sqs-lambda?ref=search

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

example-pattern.json

@bfreiberg
Copy link
Contributor

Hi @enmata and thanks for the PR. We already have two Terraform patterns that cover this behaviour: S3 -> SQS (https://serverlessland.com/patterns/s3-sqs-cdk-terraform) and SQS -> Lambda (https://serverlessland.com/patterns/sqs-lambda-terraform-python).
As patterns are supposed to be small, independent buildings builds I don't see any additional value in this submission.

@bfreiberg bfreiberg closed this Jul 8, 2024
@bfreiberg bfreiberg reopened this Jul 8, 2024
@@ -0,0 +1,81 @@
# AWS Amazon S3 Lambda with SQS queue
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# AWS Amazon S3 Lambda with SQS queue
# Amazon S3 to Amaozn SQS queue to AWS Lambda

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a "to" missing after S3

@@ -0,0 +1,81 @@
# AWS Amazon S3 Lambda with SQS queue

The terraform manifest deploys a Lambda function, an SQS queue, one S3 buckets and the IAM resources required to run the application. Create a Lambda function that is triggered on every new jpg image file stored on s3 Bucket using SQS as a notification target. The Lambda app acts as a Boilerplate code.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The terraform manifest deploys a Lambda function, an SQS queue, one S3 buckets and the IAM resources required to run the application. Create a Lambda function that is triggered on every new jpg image file stored on s3 Bucket using SQS as a notification target. The Lambda app acts as a Boilerplate code.
The Terraform code deploys an AWS Lambda function, an Amazon SQS queue, one AWS S3 buckets and the AWS IAM resources required to run the application. The created Lambda function is triggered on every new `.jpg` image file uploaded to the S3 bucket using an SQS queue as a notification target. The Lambda function code contains only contains minimal code for demo purposes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this changed in the latest commit, did you forget to include it?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, updated.

## How it works

* Use the AWS CLI or AWS console to upload an image to the source S3 Bucket
* If the object is a .jpg the code, a Lambda that is triggered using SQS as a notification target.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* If the object is a .jpg the code, a Lambda that is triggered using SQS as a notification target.
* If the object is a .jpg file, the Lambda function is triggered using SQS as a notification target.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this changed in the latest commit, did you forget to include it?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, updated.


## Testing

Run the following S3 CLI command to upload an image to the S3 bucket. Note, you must edit the {SourceBucketName} placeholder with the name of the source S3 Bucket. This is provided in the stack outputs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Run the following S3 CLI command to upload an image to the S3 bucket. Note, you must edit the {SourceBucketName} placeholder with the name of the source S3 Bucket. This is provided in the stack outputs.
Run the following AWS CLI command to upload an image to the S3 bucket. Note, you must edit the {SourceBucketName} placeholder with the name of the source S3 bucket. This is provided in the stack outputs.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, updated.


## Documentations and next step

To create a full Step Functions workflow with the pattern created, you can find out example workflows at Step Functions Workflow: [serverlessland.com/workflows](https://serverlessland.com/workflows)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To create a full Step Functions workflow with the pattern created, you can find out example workflows at Step Functions Workflow: [serverlessland.com/workflows](https://serverlessland.com/workflows)
To expand the Step Functions workflow that the pattern created, you can find out example workflows at Step Functions Workflow: [serverlessland.com/workflows](https://serverlessland.com/workflows)

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, updated.

function_name = "s3-sqs-lambda-tf-LambdaFunction"
role = aws_iam_role.MyHandlerFunction-Role.arn
handler = "app.handler"
runtime = "nodejs16.x"
Copy link
Contributor

Choose a reason for hiding this comment

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

The Nodejs v16 runtime is deprecated https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
Please use the latest Nodejs runtime

Copy link
Author

Choose a reason for hiding this comment

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

Upgrading it

console.log('value2 =', event.key2);
console.log('value3 =', event.key3);
return event.key1; // Echo back the first key value
// throw new Error('Something went wrong');
Copy link
Contributor

Choose a reason for hiding this comment

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

remove unnecessary line

Copy link
Author

Choose a reason for hiding this comment

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

I Agree, removing it

@enmata
Copy link
Author

enmata commented Jul 10, 2024

Code updated with agreed changes

@enmata
Copy link
Author

enmata commented Jul 12, 2024

Sorry, I forget to add comments changes. Now its updated.

Copy link
Contributor

@bfreiberg bfreiberg left a comment

Choose a reason for hiding this comment

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

Looks good, just one typo left. However, you are missing the example-pattern.json.

  1. Use the model template located at https://github.com/aws-samples/serverless-patterns/tree/main/_pattern-model to set up a README, template and any associated code.

  2. THIS PROCESS HAS BEEN SIMPLIFIED. All the information below must be provided in the "example-pattern.json" file cloned from the model **

The above text is taken from the new pattern template.

@@ -0,0 +1,81 @@
# Amazon S3 to Amaozn SQS queue to AWS Lambda
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Amazon S3 to Amaozn SQS queue to AWS Lambda
# Amazon S3 to Amazon SQS queue to AWS Lambda

Copy link
Author

Choose a reason for hiding this comment

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

Typo fixed, thanks.

example-pattern.json file added as an attachment on initial post on these PR. Do you want me do add it on the commit?

@bfreiberg
Copy link
Contributor

Thanks for the update. To be clear, the example-pattern.json file must be added to the PR and filled out by you with corresponding values, e.g. language, level, relevant links etc.
See here for an example from a different pattern.

@enmata
Copy link
Author

enmata commented Jul 29, 2024

Added example-pattern.json

{
"title": "S3 to Step Functions using EventBridge",
"description": "How to create an EventBridge rule with S3 as the event source and Step Functions as target.",
"language": "nodejs",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"language": "nodejs",
"language": "Node.js",

Copy link
Author

Choose a reason for hiding this comment

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

ok, changed

@@ -0,0 +1,61 @@
{
"title": "S3 to Step Functions using EventBridge",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the same title as in the README

Copy link
Author

Choose a reason for hiding this comment

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

Sorry bout the confusion, updated.

@@ -0,0 +1,61 @@
{
"title": "S3 to Step Functions using EventBridge",
"description": "How to create an EventBridge rule with S3 as the event source and Step Functions as target.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update the description to match the contents

Copy link
Author

Choose a reason for hiding this comment

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

Sorry bout the confusion, updated.

"level": "200",
"framework": "Terraform",
"introBox": {
"headline": "How to create an EventBridge rule with S3 as the event source and Step Functions as target.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update to match the actual pattern

Copy link
Author

Choose a reason for hiding this comment

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

Sorry bout the confusion, updated.

Copy link
Contributor

Choose a reason for hiding this comment

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

This still seems to be unresolved

Comment on lines 10 to 12
"This sample project demonstrates how you can trigger an execution in Step Functions state machine when an object is created in an S3 bucket.",
"When you uploads an object to the newly created S3 bucket, this will send an `Object Created` event to EventBridge, based on the EventBridge rule, the state machine is executed.",
"This pattern deploys one Step Functions state machine, one S3 bucket, one EventBridge rule."
Copy link
Contributor

Choose a reason for hiding this comment

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

see above

Copy link
Author

Choose a reason for hiding this comment

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

Sorry bout the confusion, updated.

Comment on lines 26 to 31
"text": "AWS S3 Event Notifications with EventBridge",
"link": "https://aws.amazon.com/blogs/aws/new-use-amazon-s3-event-notifications-with-amazon-eventbridge"
},
{
"text": "Using EventBridge with S3",
"link": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/EventBridge.html"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update with relevant links

Copy link
Author

Choose a reason for hiding this comment

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

Done

},
"cleanup": {
"text": [
"terraform destroy"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"terraform destroy"
"<code>terraform destroy</code>"

Copy link
Author

Choose a reason for hiding this comment

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

Good point, all code commands updated

"name": "Oriol Matavacas",
"image": "https://togithub.s3.eu-west-1.amazonaws.com/Oriol.jpg",
"bio": "Oriol Matavacas is a Sr. Solutions Architect at AWS based in Barcelona. Oriol primarily supporting customers on the journey to the Cloud. He enjoys building new solutions with scalability, availability and easy to maintain by using serverless.",
"linkedin": "https://www.linkedin.com/in/oriol-matavacas-rodriguez-b165868a",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"linkedin": "https://www.linkedin.com/in/oriol-matavacas-rodriguez-b165868a",
"linkedin": "oriol-matavacas-rodriguez-b165868a",

Copy link
Author

Choose a reason for hiding this comment

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

Done

@enmata
Copy link
Author

enmata commented Aug 16, 2024

Thanks for the comments and sorry bout the confusion. Now its updated.

"level": "200",
"framework": "Terraform",
"introBox": {
"headline": "How to create an EventBridge rule with S3 as the event source and Step Functions as target.",
Copy link
Contributor

Choose a reason for hiding this comment

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

This still seems to be unresolved

"text": [
"The terraform manifest deploys a Lambda function, an SQS queue, one S3 bucket and the IAM resources required to run the application.",
"An SQS queue consumes ObjectCreated events from an Amazon S3 bucket if the file has .jpg extension. The SQS triggers a Lambda function.",
"The Lambda app acts as a boilerplate code.",
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by this?

Copy link
Author

Choose a reason for hiding this comment

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

Explanation updated

Comment on lines 30 to 31
"text": "S3-to-Lambda serverless applications",
"link": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/EventBridge.html"
Copy link
Contributor

Choose a reason for hiding this comment

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

Link and text don't seem to match

Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that this is still resolved

Copy link
Author

Choose a reason for hiding this comment

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

Updated

"bullets": [
{
"text": "Building resilient serverless patterns by combining messaging services",
"link": "https://github.com/aws-samples/s3-to-lambda-patterns"
Copy link
Contributor

Choose a reason for hiding this comment

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

Link is outdated and doesn't really match the text

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the heads up, reference updated

@enmata
Copy link
Author

enmata commented Aug 21, 2024

Thanks for the comments, now updated its updated again.

@enmata
Copy link
Author

enmata commented Aug 26, 2024

Changes applied. Please check when you have a moment.

@@ -0,0 +1,61 @@
{
"title": "AWS Amazon S3 Lambda with SQS queue",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"title": "AWS Amazon S3 Lambda with SQS queue",
"title": "Amazon S3 to AWS Lambda with Amazon SQS queue",

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, changes applied

@@ -0,0 +1,61 @@
{
"title": "AWS Amazon S3 Lambda with SQS queue",
"description": "Create a Lambda function triggered for every jpg image file stored to S3 via SQS.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"description": "Create a Lambda function triggered for every jpg image file stored to S3 via SQS.",
"description": "Create a Lambda function that is triggered for every jpg image file uploaded to S3 via an SQS queue.",

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, changes applied

{
"title": "AWS Amazon S3 Lambda with SQS queue",
"description": "Create a Lambda function triggered for every jpg image file stored to S3 via SQS.",
"language": "node.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"language": "node.js",
"language": "Node.js",

Copy link
Author

Choose a reason for hiding this comment

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

Uppercase now

"level": "200",
"framework": "Terraform",
"introBox": {
"headline": "Create a Lambda function triggered for every jpg image file stored to S3 via SQS",
Copy link
Contributor

Choose a reason for hiding this comment

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

The headline needs to stay below 75 characters, please reword

Copy link
Author

Choose a reason for hiding this comment

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

Compressed and resumed now. Please check

"link": "https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-configure-lambda-function-trigger.html",
},
{
"text": "Amazon Simple Storage Service (S3) -> User Guide -> Using EventBridge",
Copy link
Contributor

Choose a reason for hiding this comment

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

How does EventBridge relate to the rest of the pattern? It isn't mentioned anywhere else

Copy link
Author

Choose a reason for hiding this comment

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

Right and sorry for that. Reference deleted.

Comment on lines 37 to 38
"<code>terraform init</code>",
"<code>terraform apply</code>"
Copy link
Contributor

Choose a reason for hiding this comment

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

tags can be removed here as they are automatically added to the deploy field

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

@enmata
Copy link
Author

enmata commented Sep 18, 2024

Thanks for the comments, changes applied. Please, could you review again?

@bfreiberg
Copy link
Contributor

Looks good, thanks for your contribution. Your pattern will be merged to Serverlessland.com soon

@julianwood julianwood merged commit f8d4f06 into aws-samples:main Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants