1
votes

I have written a service using AWS Step Functions. I would like to integrate this into our applications existing Elastic Beanstalk development process, wherein we have distinct dev, staging, and production applications. Each of these stages have app-specific environment variables, which I would like to pull into my Lambda functions as well.

I am not presently using SAM but I can port over if necessary to accomplish this.

The following is a simplified configuration mirroring my serverless.yml file.

service:
  name: small-service

plugins:
  - serverless-webpack
  - serverless-step-functions
  - serverless-pseudo-parameters

provider:
  name: aws
  runtime: nodejs8.10
  stage: dev
  region: us-east-2
  iamRoleStatements:
    - Effect: "Allow"
      Action:
       - "s3:*"
      Resource: { "Fn::Join": ["", ["arn:aws:s3:::S3-bucket-name", "/*" ] ] }

functions:
  connect:
    handler: handler.connect

stepFunctions:
  stateMachines:
    smallService:
      name: small-service-${self:provider.stage}
      definition:
        Comment: Service that connects to things
        StartAt: Connect
        States:
          Connect:
            Type: Task
            Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:${self:service}-${self:provider.stage}-connect
            End: true

How can I dynamically deploy the step functions into different beanstalk applications? How can I access ElasticBeanstalk environment properties from within Step Functions?

Is there a better way to import environment .env variables dynamically into a Serverless application outside of EB? We are integrating the service into a larger AWS applications development workflow, is there is a more "serverless" way of doing this?

1

1 Answers

1
votes

Move your environment variables into SSM Parameter Store. Then you can either

  1. reference SSM parameters in your serverless.yaml, or
  2. fetch SSM parameters in the beginning of each Lambda invocation (see e.g. here)

Note that the former method requires re-deploying your Lambda to receive the latest SSM parameters whereas the latter always fetches the latest parameter values.