0

I have created a small test application (just outputs some text to test) and am trying to get it so that when I have a message put into an SNS topic that my Step Function/Lambda Function will invoke and go through the Step Function flow. Below is my serverless.yml file. Hoping someone can see the issue...

service: alerting


provider:
  name: aws
  runtime: nodejs8.10
  iamRoleStatements:
    - Effect: "Allow"
      Resource: "*"
      Action:
        - "sns:*"

# you can overwrite defaults here
stage: dev
region: us-east-1


# Declare functions needed
functions:
  fetchAlerts:
    handler: handler.fetchAlerts
    events:
    - sns: arn:aws:sns:us-east-1:<account ID>:monitor_failures-${opt:stage}
    onError: arn:aws:sns:us-east-1:<account ID>:alerts-dlq
  sendFirstAlert:
    handler: handler.sendFirstAlert
    onError: arn:aws:sns:us-east-1:<account ID>:alerts-dlq
  sendFollowUp:
    handler: handler.sendFollowUp
    onError: arn:aws:sns:us-east-1:<account ID>:alerts-dlq
  responded:
    handler: handler.responded
    onError: arn:aws:sns:us-east-1:<account ID>:alerts-dlq

# Setup the step function flow
stepFunctions:
  stateMachines:
    sendAlerts:
      name: sendAlerts
      definition:
        Comment: "Blah"
        StartAt: fetchAlerts
        States:
          fetchAlerts:
            Type: Task
            Resource: "arn:aws:lambda:us-east-1:<account ID>:function:${self:service}-${opt:stage}-fetchAlerts"
            Next: sendFirstAlert
          sendFirstAlert:
            Type: Task
            Resource: "arn:aws:lambda:us-east-1:<account ID>:function:${self:service}-${opt:stage}-sendFirstAlert"
            Next: wait_60_seconds
          wait_60_seconds: 
            Type: Wait
            Seconds: 60
            Next: RespondedChoice
          RespondedChoice:
            Type: Choice
            Choices:
              - Variable: $.var
                NumericEquals: 0
                Next: sendFollowUp

              - Variable: $.var
                NumericEquals: 1
                Next: responded
          sendFollowUp:
            Type: Task
            Resource: "arn:aws:lambda:us-east-1:<account ID>:function:${self:service}-${opt:stage}-sendFollowUp"
            Next: wait_60_seconds
          responded:
            Type: Task
            Resource: "arn:aws:lambda:us-east-1:<account ID>:function:${self:service}-${opt:stage}-responded"
            Next: cleanUp
          cleanUp:
            Type: Task
            Resource: "arn:aws:lambda:us-east-1:<account ID>:function:${self:service}-${opt:stage}-cleanUp"
            End: True


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

I've included almost all of the serverless.yml only parts I removed are identifiable parts like Account ID and some comments related to the project.

If I check the AWS console for SNS I see that there is a subscription to my SNS topic for with a type of lambda so I think it should work however when I put a message into the SNS topic it does not do anything. The step functions console only shows one execution which I ran manually.

Suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.