I have a CloudFormation Template including a lambda function. The relevant parts are
AWSTemplateFormatVersion: 2010-09-09
Parameters:
Environment:
Description: Environment name
Type: String
Default: Prod
Resources:
LambdaExecutionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Policies:
- PolicyName: !Join [ '-', ['lambda-log', !Ref Environment, 'sqs-distributor'] ]
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: !GetAtt LambdaLogGroup.Arn
SqsDistributor:
Type: 'AWS::Lambda::Function'
Properties:
Code:
ZipFile: !Sub
...
...
Handler: index.handler
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: nodejs8.10
Timeout: 120
MemorySize: 128
LambdaLogGroup:
Type: 'AWS::Logs::LogGroup'
Properties:
RetentionInDays: 7
The lambda function does not work as expected, but also does not log anything to a stream when created through cloudformation
I have checked the Lambda function for syntax errors and also the ExecutionRole, which when created looks like this
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:us-east-1:765121849689:log-group:ProdSQSDistributor-LambdaLogGroup-1CVWUP6CZHAWX:*",
"Effect": "Allow"
}
]
}
The Log group is also in place as expected.