Hi team,
I'm trying to automate my stack by doing:
When I try the 4th step inside the template, the stack fails by saying:

AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
executionRole:
Type: String
Default: execution_role
s3Bucket:
Type: String
Default: functions_bucket
s3ObjectKey:
Type: String
functionName:
Type: String
Default: poc_lambda
logCollectorLambdaName:
Type: String
Default: cloudwatch-log-collector-lambda
stageName:
Type: String
Default: myTestStage
aliasName:
Type: String
Default: test
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: !Sub ${stageName}
DefinitionBody:
swagger: "2.0"
info:
title: !Sub ${functionName}
paths:
"/commerce":
get:
responses: {}
x-amazon-apigateway-integration:
uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}:${aliasName}/invocations"
httpMethod: POST
type: aws_proxy
Commerce:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Ref functionName
AutoPublishAlias: !Ref aliasName
Description: "poc lambda"
Handler: src/index.handler
Runtime: nodejs6.10
CodeUri:
Bucket: !Ref s3Bucket
Key: !Ref s3ObjectKey
Events:
Catalog:
Type: Api
Properties:
RestApiId: !Ref ApiGatewayApi
Method: GET
Path: /commerce
MemorySize: 128
Timeout: 3
Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/${executionRole}"
Tags:
name: !Ref functionName
AutoPublishAlias: !Ref aliasName
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${functionName}"
RetentionInDays: 14
LogGroupLambdaInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}"
Action: "lambda:InvokeFunction"
Principal: !Sub "logs.${AWS::Region}.amazonaws.com"
SourceArn: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${functionName}:*"
SourceAccount:
Ref: "AWS::AccountId"
DependsOn: "LogGroup"
LogsSubscriptionFilter:
Type: AWS::Logs::SubscriptionFilter
Properties:
LogGroupName: !Sub "/aws/lambda/${functionName}"
FilterPattern: ""
DestinationArn: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${logCollectorLambdaName}"
DependsOn: "LogGroupLambdaInvokePermission"
I read a lot of blogs that implement this design -
went through some of the open/closed issues in SAM -
and also did more than 50 Cloudformation deployments with different combinations to make this work.
The only workaround for having the subscription filter in the template and still make this work, is to:
In short, you won't need the AWS::Lambda::Permission in the template anymore, because AWS has that automatically created for you.
It would be very helpful if anyone can point out the issue (if any) in the template, OR assure me that this is a bug, and that I am missing something obvious.
Thanks,
Ravi Pandey.
The issue got resolved after opening a ticket with AWS support.
The problem was that the FunctionName under LogGroupLambdaInvokePermission is not the lambda function that is generating the log, but the one ingesting it. Just by changing that everything falls in place. It also makes sense that the FunctionName should be the destination arn.
I should have tried this before raising this ticket (as I already tried many other), but the reason I failed to do this was because I got a bit lost because of the documentation on this feature (steps 5 and 6 specify different log-groups). I might be misunderstanding the docs, and might have missed something straight-forward.
Anyways, this issue is resolved!
Most helpful comment
The issue got resolved after opening a ticket with AWS support.
The problem was that the
FunctionNameunderLogGroupLambdaInvokePermissionis not the lambda function that is generating the log, but the one ingesting it. Just by changing that everything falls in place. It also makes sense that the FunctionName should be the destination arn.I should have tried this before raising this ticket (as I already tried many other), but the reason I failed to do this was because I got a bit lost because of the documentation on this feature (steps 5 and 6 specify different log-groups). I might be misunderstanding the docs, and might have missed something straight-forward.
Anyways, this issue is resolved!