Skip to content

Configure docker image for aws stepfunctions local [guidance] #3538

Open
@austinben

Description

@austinben

As mentioned in a issue I submitted to aws/aws-cli#6615, I am struggling to configure the docker build that occurs when running the aws stepfunction start-execution command, which I believe invokes a docker build in the other terminal running sam local start-lambda as per https://docs.aws.amazon.com/step-functions/latest/dg/sfn-local-lambda.html .

If anyone could provide insight into how to set up local testing of stepfunctions with multiple lambda functions with various modules and dependencies? The current structure that is used for local functional testing with sam build sam local invoke is as follows:

├── index.py
├──modules1
│   ├── some_module.py
│   └── other_module.py
├──modules2
│   ├── some_module2.py
│   └── other_module2.py
├── requirements.txt
├── template.yaml
├── Dockerfile.yaml

template.yaml :

Parameters:
  EnvironmentName:
    Type: String
    Description: Environment name to prefix on resource names in this stack
  Memory:
    Type: Number
    Description: Memory (MB) allocated the lambda. This directly affects the CPU allocated
    Default: 512
  Timeout:
    Type: Number
    Description: Timeout (seconds)
    Default: 300

Resources:
  MyLambdaFunction:
    Type: AWS::Serverless::Function
    Metadata:
      DockerTag: python3.8-v1
      DockerContext: ../../../
      Dockerfile: ./lambdas/path/to/Dockerfile
    Properties:
      Description: My Lambda Function
      PackageType: Image
      Environment:
        Variables:
          AWS_ENVIRONMENT_NAME:
            Ref: EnvironmentName
      MemorySize:
        Ref: Memory
      Timeout:
        Ref: Timeout

Dockerfile :

FROM amazon/aws-lambda-python:3.8

COPY lambdas/path/to/index.py lambdas/path/to/requirements.txt ./
ADD ./modules/somemodules ./somemodules
ADD ./modules/somemodules2 ./somemodules2
RUN python3.8 -m pip install -r requirements.txt -t .

CMD ["index.lambda_handler"]

This works correctly just using sam build and sam local invoke -e for functional testing, (and for debugging in VSCode after creating a launch.json.

I have multiple of these Lambda functions, each composing a portion of a step function defined in a .json template, along with everything else in a cloudformation .json template.

Is it possible to use the aws stepfunctions local tool with multiple lambdas defined in this way? Currently, it seems to just build the image from some default settings, and I cant seem to configure it as I have with the individual tests.

If this is too off-topic for this issue I am happy to open a new issue, I was directed here as the build process seems to be from the SAM CLI but the stepfunctions portion of the workflow if from the AWS CLI, please advise! Thanks :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions