Testing Step Functions w/SAM - Connection refused

1

Problem

Attempting to following the Testing Step Functions and AWS SAM CLI Local instructions, but when I Executed my Local State Machine (Step 6), I got the following error in stdout from the docker terminal tab:

2023-05-03 15:49:39.856: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test : {"Type":"LambdaFunctionFailed","PreviousEventId":4,"LambdaFunctionFailedEventDetails":{"Error":"Lambda.SdkClientException","Cause":"Unable to execute HTTP request: Connect to localhost:3001 [localhost/127.0.0.1] failed: Connection refused (Connection refused)"}}

Environment

  • Running on a MacBook Pro, Apple M1 Pro chip, Ventura 13.3.1
  • aws-sam-cli-macos-arm64.pkg
    • SAM CLI, version 1.82.0
  • Docker version 23.0.5, build bc4487a
  • aws-cli/2.10.3 Python/3.9.11 Darwin/22.4.0 exe/x86_64 prompt/off

Setup

Started SAM

> sam local start-api
> sam local start-lambda

Started Docker:

docker run -p 8083:8083 --env-file ~/docker/aws-stepfunctions-local-credentials.txt amazon/aws-stepfunctions-local

My ~/docker/aws-stepfunctions-local-credentials.txt file:

LAMBDA_ENDPOINT=http://localhost:3001

Details

Full docker stdout

~: docker run -p 8083:8083 --env-file ~/docker/aws-stepfunctions-local-credentials.txt amazon/aws-stepfunctions-local
Step Functions Local
Version: 1.12.0
Build: 2022-11-21
2023-05-03 16:01:45.288: Configure [LAMBDA_ENDPOINT] to [http://localhost:3001]
2023-05-03 16:01:45.297: Failed to load credentials from environment because Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY))
2023-05-03 16:01:45.316: Failed to load credentials from profile: default because profile file cannot be null
2023-05-03 16:01:45.316: Failed to load credentials from system properties because Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey)
2023-05-03 16:01:45.316: Failed to load credentials, default to dummy credentials, so any connection to AWS services will not work, connections to local endpoints are not affected.
2023-05-03 16:01:45.561: Starting server on port 8083 with account 123456789012, region us-east-1
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2023-05-03 16:01:56.872: CreateStateMachine => {"requestClientOptions":{"readLimit":131073,"skipAppendUriPath":false},"requestMetricCollector":null,"customRequestHeaders":null,"customQueryParameters":null,"cloneSource":null,"sdkRequestTimeout":null,"sdkClientExecutionTimeout":null,"name":"HelloWorld","definition":"{  \"Comment\": \"A Hello World example of the Amazon States Language using an AWS Lambda Local function\",  \"StartAt\": \"HelloWorld\",  \"States\": {    \"HelloWorld\": {      \"Type\": \"Task\",      \"Resource\": \"arn:aws:lambda:us-east-1:123456789012:function:HelloWorldFunction\",      \"End\": true    }  }}}}","roleArn":"arn:aws:iam::012345678901:role/DummyRole","type":null,"loggingConfiguration":null,"tags":null,"tracingConfiguration":null,"requestCredentials":null,"requestCredentialsProvider":null,"generalProgressListener":{"syncCallSafe":true},"readLimit":131073,"cloneRoot":null}
2023-05-03 16:01:56.890: [200] CreateStateMachine <= {"sdkResponseMetadata":null,"sdkHttpMetadata":null,"stateMachineArn":"arn:aws:states:us-east-1:123456789012:stateMachine:HelloWorld","creationDate":1683129716882}
2023-05-03 16:02:04.432: StartExecution => {"requestClientOptions":{"readLimit":131073,"skipAppendUriPath":false},"requestMetricCollector":null,"customRequestHeaders":null,"customQueryParameters":null,"cloneSource":null,"sdkRequestTimeout":null,"sdkClientExecutionTimeout":null,"stateMachineArn":"arn:aws:states:us-east-1:123456789012:stateMachine:HelloWorld","name":"test","input":null,"traceHeader":null,"requestCredentials":null,"requestCredentialsProvider":null,"generalProgressListener":{"syncCallSafe":true},"readLimit":131073,"cloneRoot":null}
2023-05-03 16:02:04.453: [200] StartExecution <= {"sdkResponseMetadata":null,"sdkHttpMetadata":null,"executionArn":"arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test","startDate":1683129724450}
2023-05-03 16:02:04.459: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test : {"Type":"ExecutionStarted","PreviousEventId":0,"ExecutionStartedEventDetails":{"Input":"{}","RoleArn":"arn:aws:iam::012345678901:role/DummyRole"}}
2023-05-03 16:02:04.460: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test : {"Type":"TaskStateEntered","PreviousEventId":0,"StateEnteredEventDetails":{"Name":"HelloWorld","Input":"{}"}}
2023-05-03 16:02:04.466: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test : {"Type":"LambdaFunctionScheduled","PreviousEventId":2,"LambdaFunctionScheduledEventDetails":{"Resource":"arn:aws:lambda:us-east-1:123456789012:function:HelloWorldFunction","Input":"{}"}}
2023-05-03 16:02:04.467: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test : {"Type":"LambdaFunctionStarted","PreviousEventId":3}
2023-05-03 16:02:04.553: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test : {"Type":"LambdaFunctionFailed","PreviousEventId":4,"LambdaFunctionFailedEventDetails":{"Error":"Lambda.SdkClientException","Cause":"Unable to execute HTTP request: Connect to localhost:3001 [localhost/127.0.0.1] failed: Connection refused (Connection refused)"}}
2023-05-03 16:02:04.555: arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test : {"Type":"ExecutionFailed","PreviousEventId":5,"ExecutionFailedEventDetails":{"Error":"Lambda.SdkClientException","Cause":"Unable to execute HTTP request: Connect to localhost:3001 [localhost/127.0.0.1] failed: Connection refused (Connection refused)"}}

Full SAM lambda stdout

~/sam-app: sam local start-lambda
Initializing the lambda functions containers.
Local image is up-to-date
Using local image: public.ecr.aws/lambda/python:3.9-rapid-x86_64.

Mounting /Users/blusigna/sam-app/.aws-sam/build/HelloWorldFunction as /var/task:ro,delegated, inside runtime container
Containers Initialization is done.
Starting the Local Lambda Service. You can now invoke your Lambda Functions defined in your template through the endpoint.
2023-05-03 11:51:08 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:3001
2023-05-03 11:51:08 Press CTRL+C to quit

AWS stdout

~: aws stepfunctions --endpoint http://localhost:8083 create-state-machine --definition "{\
  \"Comment\": \"A Hello World example of the Amazon States Language using an AWS Lambda Local function\",\
  \"StartAt\": \"HelloWorld\",\
  \"States\": {\
    \"HelloWorld\": {\
      \"Type\": \"Task\",\
      \"Resource\": \"arn:aws:lambda:us-east-1:123456789012:function:HelloWorldFunction\",\
      \"End\": true\
    }\
  }\
}\
}}" --name "HelloWorld" --role-arn "arn:aws:iam::012345678901:role/DummyRole"
{
    "stateMachineArn": "arn:aws:states:us-east-1:123456789012:stateMachine:HelloWorld",
    "creationDate": "2023-05-03T12:01:56.882000-04:00"
}
~: 
~: 
~: 
~: aws stepfunctions --endpoint http://localhost:8083 start-execution --state-machine arn:aws:states:us-east-1:123456789012:stateMachine:HelloWorld --name test
{
    "executionArn": "arn:aws:states:us-east-1:123456789012:execution:HelloWorld:test",
    "startDate": "2023-05-03T12:02:04.450000-04:00"
}
Brian
gefragt vor einem Jahr393 Aufrufe
1 Antwort
0

If you are on Windows you should change this

LAMBDA_ENDPOINT=http://localhost:3001

to this

LAMBDA_ENDPOINT=http://host.docker.internal:3001
Mikhail
beantwortet vor 9 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen