Search code examples
dockeraws-step-functionsmoto

404 Error with "local" Step Functions State Machine calling moto_server on host


Using AWS Step Functions State Machine (SFSM) in "local" mode, ie running inside Docker on my laptop

Trying to run a task pointing to a mocked service on my laptop host

I can install SFSM correctly on Docker, update it, run it

aws stepfunctions --endpoint http://localhost:8083 create-state-machine \
    --definition file://src/my_sfn.json \
    --role-arn 'arn:aws:iam::ACCTNUM:role/DummyRole' \
    --name my_sfn

I can run curl http://host.docker.internal:5000 from docker and connect to the moto_server

I installed aws cli on the SFSM container, and ran aws sns --endpoint http://host.docker.internal:5000 list-topics and it showed the correct topics

I set up the SNS_ENDPOINT url in my docker env file to point to host machine

But I always get 404 Not Found errors if running the SFSM:

2021-03-04 18:59:24.472: arn:aws:states:us-east-1:ACCTNUM:execution:my_sfn:7151fcf4-7e6f-4b16-9b64-2ac913e27e4c : {"Type":"TaskSubmitFailed","PreviousEventId":4,"TaskSubmitFailedEventDetails":{"ResourceType":"sns","Resource":"publish","Error":"SNS.AmazonSNSException","Cause":"null (Service: AmazonSNS; Status Code: 404; Error Code: 404 NOT FOUND; Request ID: null; Proxy: null)"}}
2021-03-04 18:59:24.473: arn:aws:states:us-east-1:ACCTNUM:execution:my_sfn:7151fcf4-7e6f-4b16-9b64-2ac913e27e4c : {"Type":"ExecutionFailed","PreviousEventId":5,"ExecutionFailedEventDetails":{"Error":"SNS.AmazonSNSException","Cause":"null (Service: AmazonSNS; Status Code: 404; Error Code: 404 NOT FOUND; Request ID: null; Proxy: null)"}}

my_sfn.json:

{
    "StartAt": "step1",
    "States": {
        "step1": {
            "Type": "Task",
            "Resource": "arn:aws:states:::sns:publish",
            "Parameters":{
                "Message":{"Input":"howdy"},
                "TopicArn":"arn:aws:sns:us-west-2:ACCTNUM:foo"
            },
            "End": true
        }
    }
}

docker-env.txt:

SNS_ENDPOINT=http://host.docker.internal:5000

Any idea how to fix?


Solution

  • Looks like I had to add more info to the environment file:

    AWS_ACCOUNT_ID=123456789012
    AWS_ACCESS_KEY_ID=AAAAAAAAAAAAAAAA
    AWS_SECRET_ACCESS_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AWS_DEFAULT_REGION=us-west-2
    

    Used the same account id and region consistently, and it worked