Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How you Reference the function ARN of a Function (Lambda) in serverless.yml file?

Considering this lambda function on a serverless.yml file:

functions:
  s3toEc2Lambda:
    handler: s3toec2lambda.S3toEc2Lambda
    name: "${self:service}-s3toEc2Lambda"
    role: S3toEc2LambdaRole

And considering this SNS created on resources section: Does someone knows how to inform the Sns ARN Endpoint from the lambda function s3toEc2Lambda ?

resources:
  Resources:
    WordpressFrontEndSnsS3toEc2:
      Type: AWS::SNS::Topic
      Properties:
        TopicName: "wordpress-front-end-s3-ec2"

    WordpressFrontEndSnsS3toEc2Lambda:
      Type: AWS::SNS::Subscription
      Properties:
        Endpoint: { "Fn::GetAtt": ["s3toEc2Lambda", "Arn" ] }                    <------ HERE    <------
        #Endpoint: ${self:functions.s3toEc2Lambda}                               <------ OR HERE <------
        #Endpoint: { "Fn::GetAtt": ["${self:functions.s3toEc2Lambda}", "Arn" ] } <------ OR HERE <------
        Protocol: lambda
        TopicArn: !Ref 'WordpressFrontEndSnsS3toEc2'

For me always appear a error message like this: "Template error: instance of Fn::GetAtt references undefined resource s3toEc2Lambda"

Thank You !

like image 845
Carlos Valença de Paula Avatar asked May 24 '20 20:05

Carlos Valença de Paula


People also ask

How do I refer to a property in serverless Yaml file?

To reference properties in other YAML files use the ${file(./myFile. yml):someProperty} syntax in your serverless. yml configuration file. To reference properties in other JSON files use the ${file(./myFile.

What is lambda function Arn?

An Amazon Resource Name (ARN) is a file naming convention used to identify a particular resource in AWS and they uniquely identify AWS resources. If you successfully created a Lambda function (Independently if it is triggered by Alexa Skills Kit or not) you will get an ARN.

How do I run lambda functions in a serverless service?

All of the Lambda functions in your serverless service can be found in serverless.yml under the functions property. reservedConcurrency: 5 # optional, reserved concurrency limit for this function. By default, AWS uses account concurrency limit The handler property points to the file and module containing the code you want to run in your function.

What is a lambda function url?

A Lambda Function URL is a simple solution to create HTTP endpoints with AWS Lambda. Function URLs are ideal for getting started with AWS Lambda, or for single-function applications like webhooks or APIs built with web frameworks. You can create a function URL via the url property in the function configuration in serverless.yml.

Is lambda function a resource?

I always thought the lambda function declaration was also considered a resource (besides the obvious Resources: block of course), perhaps I am misunderstanding something. Show activity on this post. I figured it out. I had a NodeJS project and was using the "serverless" command line (sls) to deploy using serverless.yml.

What is the default architecture for lambda functions?

By default, Lambda functions are run by 64-bit x86 architecture CPUs. However, using arm64 architecture (AWS Graviton2 processor) may result in better pricing and performance. To switch all functions to AWS Graviton2 processor, configure architecture at provider level as follows: ...


Video Answer


1 Answers

CloudFormation resources created by serverless have known format. For lambda function this is:

{normalizedFunctionName}LambdaFunction

Thus you should be able to reference your function using the following:

"Fn::GetAtt": [ S3toEc2LambdaLambdaFunction, Arn ]

More example about this are here

like image 82
Marcin Avatar answered Oct 28 '22 07:10

Marcin