Gary Holiday
Gary Holiday

Reputation: 3562

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.

Upvotes: 2

Views: 4786

Answers (1)

Dejan Peretin
Dejan Peretin

Reputation: 12089

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}:*'

Upvotes: 7

Related Questions