[Solved] Get a AWS CF resource ID inside Lambda?

Hi,

I’m creating some resources on my serverless.yml with cloudformation.
Is it possible to get the IDs of those resources inside the lambdas so that I don’t need to hard-coded all the IDs of the resources created?

Thanks

You can reference cloudformation values like so https://github.com/DavidWells/serverless-workshop/blob/master/lessons-code-complete/events/dynamodb-streams/serverless.yml#L21 and pass them in an environment variables

more info here http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html

1 Like

Thanks!

I’m trying to do this with a Cognito Identity Pool but I get the error:

/Resources/IamRoleLambdaExecution/Properties/Policies/0/PolicyDocument/Statement/2/Resource/0/Fn::Join/1/0/Fn::GetAtt: Resource type AWS::Cognito::IdentityPool does not support
attribute {Arn}.

This doesn’t work with a Cognito Identity Pool?

Ok, now it’s working.

What I did was:

  Resource:
    - 'Fn::Join':
      - ''
      -
        - 'arn:aws:cognito-sync:eu-west-2:1111111111:identitypool/'
        - Ref: CognitoIdentityPool
        - '/identity/*/dataset/*'

And for environment I did like you have:

provider:
  name: aws
  runtime: nodejs6.10
  stage: ${opt:stage, 'dev'}
  environment:
    IDENTITY_POOL_ID: { Ref: CognitoIdentityPool }

Thanks!

1 Like