简体   繁体   中英

How do I get the log group name and ARN of a lambda generated by CloudFormation?

I'm generating a lambda in CloudFormation like this:

TestFunction:
  Type: AWS::Serverless::Function
  Properties:
    Handler: lib/test.handler
    Timeout: 30
    Role: !GetAtt ExecutionRole.Arn

Now, CloudFormation will automatically create me a log group for this lambda. How do I access that log groups name and ARN?

I do NOT want to create a log group and then associate it to my lambda. I want to access the log group that is created for me automatically.

Log group created by a lambda function will have a name of the form /aws/lambda/<function name> . See here: https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions-logs.html

You can construct the name of the log group with:

!Sub '/aws/lambda/${TestFunction}'

and the arn:

!Sub 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${TestFunction}:*'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM