Tal Ben Shalom
Tal Ben Shalom

Reputation: 123

how to set existing kinesis stream arn in function event

I'm using serverless framework and trying to deploy Lambda function with event/trigger definition. The event source is Kinesis stream that already exist. I'm trying to set the stream ARN with Fn::Join function, but it seems not supported. How can I set the event stream ARN without hard coding the AWS region and account Id?

My yml code:

functions:
    myfunction:
    handler: myfunction.handler
    name: myfunction-name
    memorySize: 128
    timeout: 120
    events:
      - stream:
          type: kinesis
          arn:
            Fn::Join:
              - ""
              - - "arn:aws:kinesis:"
                - Ref: AWS::Region
                - ":"
                - Ref: AWS::AccountId
                - ":stream/xxxxxxx"
          batchSize: 300
          startingPosition: LATEST
          enabled: true

Upvotes: 1

Views: 895

Answers (2)

Chris Pollard
Chris Pollard

Reputation: 1780

I like the simplicity and readibility of the sub function over the join.

!Sub arn:aws:kinesis:${AWS::Region}:${AWS::AccountId}:stream/xxxx

Rereading that it relates to the serverless framework, I'd leverage this plugin: https://www.npmjs.com/package/serverless-pseudo-parameters

Upvotes: 1

arr
arr

Reputation: 19

use Fn::GetAtt.

from aws documentation:

Fn::GetAtt

returns a value for the Arn attribute.

Arn

The Amazon resource name (ARN) of the Kinesis stream, such as arn:aws:kinesis:us-east-2:123456789012:stream/mystream.

For more information about using Fn::GetAtt, see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html

Upvotes: 0

Related Questions