Skip to content

jeromemacias/serverless-step-functions-local

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serverless-step-functions-offline

Run AWS step functions offline with Serverless!

On Serverless online start this plugin will create state machine defined on the serverless configuration file.

This is a plugin for the Serverless Framework.

Requirements

Install

npm install @jeromemacias/serverless-step-functions-offline -D

Getting Started

You'll need to add this plugin to your serverless.yml. The plugins section should look something like this when you're done:

plugins:
  ...
  - serverless-step-functions
  - serverless-step-functions-offline
  - serverless-offline
  ...

Then, add a new section to config with accountId and region parameters:

custom:
  step-functions-offline:
    accountId: 101010101010
    region: us-east-1

It also adds an environment variable for each created state machine that contains the ARN for it. These variables are prefixed by OFFLINE_STEP_FUNCTIONS_ARN_, so the ARN of a state machine named 'WaitMachine', for example could be fetched by reading OFFLINE_STEP_FUNCTIONS_ARN_WaitMachine.

Options

(These go under custom.step-functions-offline.)

  • accountId (required) your AWS account ID
  • region (required) your AWS region
  • stepFunctionsEndpoint (defaults to http://localhost:8083) the endpoint for the AWS step functions local service
  • TaskResourceMapping allows for Resource ARNs to be configured differently for local development

Full Config Example

service: offline-step-function

plugins:
  - serverless-step-functions
  - serverless-step-functions-offline
  - serverless-offline

provider:
  name: aws
  runtime: nodejs14.x


custom:
  step-functions-offline:
    accountId: 101010101010
    region: us-east-1
    TaskResourceMapping:
      FirstState: arn:aws:lambda:us-east-1:101010101010:function:hello
      FinalState: arn:aws:lambda:us-east-1:101010101010:function:hello
  sqsUrl: http://localhost:4566/101010101010/example-queue

functions:
  hello:
    handler: handler.hello

stepFunctions:
  stateMachines:
    WaitMachine:
      definition:
        Comment: "An example of the Amazon States Language using wait states"
        StartAt: FirstState
        States:
          FirstState:
            Type: Task
            Resource: Fn::GetAtt: [hello, Arn]
            Next: send_message
          send_message:
            Type: Task
            Resource: arn:aws:states:::sqs:sendMessage
            Parameters:
              QueueUrl: ${self:custom.sqsUrl}
              "MessageBody.$": "$"
            Next: wait_using_seconds
          wait_using_seconds:
            Type: Wait
            Seconds: 10
            Next: FinalState
          FinalState:
            Type: Task
            Resource: Fn::GetAtt: [hello, Arn]
            End: true

About

Run AWS step functions offline with Serverless

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%