Using Lambda and SQS with App Runner for background processing
Copy the variables template files:
cp infra/config/local.auto.tfvars infra/.auto.tfvarsGo to the
Important
Enable Lambda Application Insights
Create the infrastructure:
terraform -chdir="infra" init
terraform -chdir="infra" apply -auto-approveBuild and push the API application to ECR:
cd api
bash ecrBuildPush.shFlag the App Runner for deployment and re-apply the infrastructure:
enable_app_runner = trueVPC 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.comNetwork connectivity:
# Expect an error response
curl https://secretsmanager.us-east-2.amazonaws.comReal access needs to be tested with approved credentials.
Tip
Keep the AWS SAM CLI updated.
./mvnw spring-boot:runTest the API:
curl -I -u lambda:p4ssw0rd localhost:8080To enqueue new messages:
# With BASIC authentication
curl -X POST -d "response status" https://example.com/api/enqueueFor 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/secretThe application will use default Spring Security auto-configuration with the following credentials:
| Component | Username | Password |
|---|---|---|
| Client | client |
p4ssw0rd |
| SQS Lambda | lambda |
p4ssw0rd |
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
| Language | Runtime | Password |
|---|---|---|
| Java | java21 |
p4ssw0rd |
| Python | python3.13 |
p4ssw0rd |
To recreate the ZIP file:
zip -r lambda-java.zip ioTerraform parameters:
lambda_handler_zip = "java/lambda-java.zip"
lambda_runtime = "java21"
lambda_handler = "io.pomatti.lambda.Function::handleRequest"To recreate the ZIP file:
zip lambda-python.zip app.pyTerraform parameters:
lambda_handler_zip = "python/lambda-python.zip"
lambda_runtime = "python3.13"
lambda_handler = "app.lambda_handler"