Skip to content

epomatti/aws-apprunner-lambda-sqs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS AppRunner SQS Trigger with Lambda

Using Lambda and SQS with App Runner for background processing

Infrastructure Deployment

Copy the variables template files:

cp infra/config/local.auto.tfvars infra/.auto.tfvars

Go to the

Important

Enable Lambda Application Insights

Create the infrastructure:

terraform -chdir="infra" init
terraform -chdir="infra" apply -auto-approve

Build and push the API application to ECR:

cd api
bash ecrBuildPush.sh

Flag the App Runner for deployment and re-apply the infrastructure:

enable_app_runner = true

VPC Endpoints

VPC Endpoint access is implemented via endpoint policies.

Additional configuration and requirements are needed for VPC connectivity. Check the requirements that fit your use case.

Traffic can be denied from outside the VPC. Check the example 5.

Checking resolution:

dig secretsmanager.us-east-2.amazonaws.com

Network connectivity:

# Expect an error response
curl https://secretsmanager.us-east-2.amazonaws.com

Real access needs to be tested with approved credentials.

Local Development

Tip

Keep the AWS SAM CLI updated.

./mvnw spring-boot:run

Test the API:

curl -I -u lambda:p4ssw0rd localhost:8080

API

To enqueue new messages:

# With BASIC authentication
curl -X POST -d "response status" https://example.com/api/enqueue

For the process API, this should be sent via Lambda, but with for direct tests:

{
	"httpResponseStatus": 200
}

To get a Secrets Manager string value:

curl https://example.com/api/secret

Authentication

The application will use default Spring Security auto-configuration with the following credentials:

Component Username Password
Client client p4ssw0rd
SQS Lambda lambda p4ssw0rd

Lambda

https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html

Language Runtime Password
Java java21 p4ssw0rd
Python python3.13 p4ssw0rd

Runtimes

Java

To recreate the ZIP file:

zip -r lambda-java.zip io

Terraform parameters:

lambda_handler_zip = "java/lambda-java.zip"
lambda_runtime     = "java21"
lambda_handler     = "io.pomatti.lambda.Function::handleRequest"

Python

To recreate the ZIP file:

zip lambda-python.zip app.py

Terraform parameters:

lambda_handler_zip = "python/lambda-python.zip"
lambda_runtime     = "python3.13"
lambda_handler     = "app.lambda_handler"

Reference

About

Lambda and SQS with App Runner for background processing

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors