5
votes

I am using Serverless framework for deployment of my AWS Lambda functions. I have a serverless.yml file which declares all of my resources and functions.

For example:


...
resources:
  Resources:
    MyTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: my-table
        AttributeDefinitions:
          -
            AttributeName: "id"
            AttributeType: "S"
        KeySchema:
          -
            AttributeName: "id"
            KeyType: "HASH"
        ProvisionedThroughput:
          ReadCapacityUnits: "5"
          WriteCapacityUnits: "5"
        StreamSpecification:
          StreamViewType: NEW_AND_OLD_IMAGES
    ...      
...
my-handler:
    ...
    events:
      - stream:
          type: dynamodb
          arn: ...

My Lambda function is triggered from DynamoDB stream. So in the event definition, how can I reference to DynamoDB stream of "MyTable" without hard-coding its ARN?

1

1 Answers

3
votes

You can use AWS CloudFormation intrinsic functions like this:

events:
  - stream:
      type: dynamodb
      arn:
        Fn::GetAtt: [ MyTable, StreamArn ]