Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
I have Lamba function in a form of a docker image with a handler like
def routing_local(event, context):
raise Exception("omg")
When I run the State Machine, I'm getting LambdaFunctionSucceeded
response, which break State Machine retry logic.
localstack_main | 2021-07-06 14:57:47.884: arn:aws:states:us-east-1:000000000000:execution:upgrade-properties-local:2021-07-06-14-57-45 : {"Type":"LambdaFunctionSucceeded","PreviousEventId":4,"LambdaFunctionSucceededEventDetails":{"Output":"{\"errorMessage\": \"omg\", \"errorType\": \"Exception\", \"stackTrace\": [\" File \\\"/var/task/handler.py\\\", line 4, in routing_local\\n raise Exception()\\n\"]}"}}
Expected Behavior
Have to see LambdaFunctionFailed
type if the hander raises an exception.
How are you starting LocalStack?
With a docker-compose file
Steps To Reproduce
How are you starting localstack (e.g., bin/localstack
command, arguments, or docker-compose.yml
)
version: "3.9"
services:
automation:
container_name: automation
build:
dockerfile: automation/step-functions-handler/Dockerfile
context: "../.."
ports:
- "8080:8080"
environment:
- ....
volumes:
- ~/.aws/:/root/.aws:ro
command: ["handler.routing_local"]
localstack:
depends_on:
- automation
container_name: localstack_main
image: localstack/localstack
environment:
- DATA_DIR=/tmp/localstack/data
- HOST_TMP_FOLDER=/tmp/localstack
- SERVICES=stepfunctions
- TZ=America/New_York
- LAMBDA_ENDPOINT=http://automation:8080/
- REGION=us-east-1
- STEPFUNCTIONS_LAMBDA_ENDPOINT=http://automation:8080/
- DEBUG=1
ports:
- '4574:4574'
- '4568:4568'
- '4569:4569'
- '4582:4582'
- '4566:4566'
volumes:
- ~/.aws/:/root/.aws:ro
- /tmp/localstack:/tmp/localstack
- /var/run/docker.sock:/var/run/docker.sock
An automation/step-functions-handler/Dockerfile looks like
FROM public.ecr.aws/lambda/python:3.8 as app
# copy all installed packages
COPY --from=builder /var/lang/lib/python3.8/site-packages /var/lang/lib/python3.8/site-packages
COPY --from=builder ${LAMBDA_TASK_ROOT} ${LAMBDA_TASK_ROOT}
# see https://docs.datadoghq.com/serverless/installation/python/?tab=containerimage
#CMD [ "datadog_lambda.handler.handler" ]
CMD ["handler.routing_local"]
State Machine can be as simple as:
StartAt: CreateEnrollment
States:
CreateEnrollment:
Type: Task
Resource: arn:aws:lambda:us-east-1:000000000000:function:function
Parameters:
action: CREATE_ENROLLMENT
certName.$: $.certName
certType.$: $.certType
hostnameAdded: "false"
orgId.$: $.orgId
propertyVersion: NA
reportingGroupId: "NONE"
taskType.$: $.taskType
botContext.$: $.botContext
taskId.$: $$.Execution.Id
Catch:
- ErrorEquals: ["States.ALL"]
Next: CreateEnrollmentError
Next: GetEnrollment
CreateEnrollmentError:
Type: Fail
Error: CreateEnrollment
Cause: Error creating Enrollment
docker compose up
Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)
Create State Machine
awslocal stepfunctions \
--no-cli-pager \
create-state-machine \
--definition file://./state-machine.json \
--name "$(name)-local" \
--role-arn arn:aws:iam::000000000000:role/DummyRole
Start Execution of the State Machine
awslocal stepfunctions \
--no-cli-pager \
start-execution \
--state-machine arn:aws:states:us-east-1:000000000000:stateMachine:$(name)-local \
--name `date "+%Y-%m-%d-%H-%M-%S"` \
--input file://./payloads/$(name).json
Environment
- OS: Catalina 10.15.7 (19H1217)
- Lambda: public.ecr.aws/lambda/python:3.8@sha256:6f585646ae61da5a01e31edfa4e1d31a096bacd43a8c24dcf445eb5da7eac119
- LocalStack: latest
Anything else?
I'm using Lambda Container Images to run the lambda code
https://docs.aws.amazon.com/lambda/latest/dg/images-create.html
The ARN of the Lambda Resource should be set to arn:aws:lambda:us-east-1:000000000000:function:function
to conform to the http://localhost:9000/2015-03-31/functions/function/invocations
API call format