SQS / SNS / Lambda

Hi all,

I’m really struggling to link up my services. Heres a basic flow of what i’m trying to achieve:

  • SQS receiving messages - working
  • CloudWatch Alarms on queue length post to SNS - working
  • SNS Topic triggers scale Lambda function - attached to the lambda but no events are coming through

Here is my serverless config. I’m not sure if i’m missing something glaringly obvious. Any help would be appreciated

service: sls-sqs-test

useDotenv: true

plugins:
  - serverless-webpack
  - serverless-sqs-alarms-plugin
  - serverless-offline-sqs
  - serverless-offline

provider:
  name: aws
  runtime: nodejs12.x
  region: eu-west-1
  stage: dev
  lambdaHashingVersion: 20201221
  tracing:
    lambda: true

custom:
  stage: ${opt:stage, self:provider.stage}
  prefix: ${self:custom.stage}-${self:service}
  process: ${self:custom.prefix}-process
  config: ${self:custom.prefix}-config
  sns: ${self:custom.prefix}-trigger
  sqs: ${self:custom.prefix}-messages
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true

  sqs-alarms:
    - queue: messages
      topic: dev-sls-sqs-test-trigger
      thresholds:
        - 1
        - 10
        - 50
        - 100
        - 500
        - 1000
        - 5000

functions:
  scale:
    timeout: 10
    handler: scale.handler
    name: scale
    environment:
      config: config
    events:
      - sns: dev-sls-sqs-test-trigger

resources:
  Resources:
    Messages:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: messages
        MessageRetentionPeriod: 1209600
        VisibilityTimeout: 60
        RedrivePolicy:
          deadLetterTargetArn:
            Fn::GetAtt:
            - MessagesDeadLetterQueue
            - Arn
          maxReceiveCount: 10

    MessagesDeadLetterQueue:
      Type: AWS::SQS::Queue
      Properties:
        QueueName: dead-letter-queue
        MessageRetentionPeriod: 1209600

    Config:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: config
        AttributeDefinitions:
          - AttributeName: key
            AttributeType: S
        KeySchema:
          - AttributeName: key
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 5
          WriteCapacityUnits: 5