0
votes

i created a log group for my lambda using cloud formation, and i when i run my cloudformation scripts, the lambda function includes the cloudwatch log trigger. When i invoke the lambda, the log group i created using the cloudformation doesn’t have any log stream in it, but it seems cloudformation automatically creates a log group for the lambda regardless if i am creating one using cloudformation and including it to the function.

Is there any advice please?

'''

resources:
  Resources:
    AccessLogs:
      Type: AWS::Logs::LogGroup
      Properties:
        LogGroupName: /aws/lambda/${self:service}-dev-AccessLogs
        RetentionInDays: 7
    LambdaExecutionRole:
      Type: 'AWS::IAM::Role'
      Properties:
        AssumeRolePolicyDocument:
          Statement:
            - Effect: Allow
              Principal:
                Service:
                  - lambda.amazonaws.com
              Action:
                - 'sts:AssumeRole'
        Policies:
        - PolicyName: logpolicy
          PolicyDocument:
            Statement:
              - Effect: Allow
                Action:
                  - 'logs:CreateLogGroup'
                  - 'logs:CreateLogStream'
                Resource: '*'
              - Effect: Allow
                Action:
                  - 'logs:PutLogEvents'
                Resource: 'arn:aws:logs:*:*:*'

'''
1

1 Answers

1
votes

You cannot assign an arbitrary log group to a Lambda function. There's an open Feature Request for it.

If you simply want to change the log retention policy then you might be able to do that using this technique, but it still does not allow you to control the log group name.