Enabling API Gateway Logs in serverless.yml tries to create new IAM Role and a new Lambda
See original GitHub issueBug Report
Description
- What did you do?
logs:
restApi: # Optional configuration which specifies if API Gateway logs are used. This can either be set to true to use defaults, or configured via subproperties.
executionLogging: true # Optional configuration which enables or disables execution logging. Defaults to true.
level: INFO # Optional configuration which specifies the log level to use for execution logging. May be set to either INFO or ERROR.
fullExecutionData: true # Optional configuration which specifies whether or not to log full requests/responses for execution logging. Defaults to true.
role: <role that allows pushing to logs to cloudwatch>#
I have added this configuration in my serverless.yml file to enable cloudwatch logging for API gateway.
- What happened? I got the following error while I tried to deploy
An error occurred: IamRoleCustomResourcesLambdaExecution - API: iam:CreateRole User: arn:aws:sts::<some role name> is not authorized to perform: iam:CreateRole on resource: arn:aws:iam::<some resource name>with an explicit deny
I have restricted access to this account and i dont have access to create IAM roles.I have observed that it tries to create a role (IamRoleCustomResourcesLambdaExecution
) and new Lambda -custom-resource-apigw-cw-role
-
What should’ve happened? It should have enabled cloudwatch logs for API gateway
-
What’s the content of your
serverless.yml
file?
# along with other resources
logs:
restApi: # Optional configuration which specifies if API Gateway logs are used. This can either be set to true to use defaults, or configured via subproperties.
executionLogging: true # Optional configuration which enables or disables execution logging. Defaults to true.
level: INFO # Optional configuration which specifies the log level to use for execution logging. May be set to either INFO or ERROR.
fullExecutionData: true # Optional configuration which specifies whether or not to log full requests/responses for execution logging. Defaults to true.
role: <role to write to cloudwatch> #
Similar or dependent issues:
- #6134 This issue was closed with suggesting a resolution.Hence creating another issue.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:30 (16 by maintainers)
Top Results From Across the Web
Apigateway cloudwatch log group role - Serverless Framework
I have serverless to deploy api gateways to aws. ... Enabling API Gateway Logs in serverless.yml tries to create new IAM Role and...
Read more >REST API (API Gateway v1) - Serverless Framework
To create HTTP endpoints as Event sources for your AWS Lambda Functions, use the Serverless Framework's easy AWS API Gateway Events syntax.
Read more >AWS Lambda Guide - Serverless.yml Reference
The Serverless Framework documentation for AWS Lambda, API Gateway, EventBridge, DynamoDB and much more.
Read more >CloudWatch Log - AWS Lambda Events - Serverless Framework
Simple event definition ... This will enable your Lambda function to be called by a Log Stream. ... WARNING: If you specify several...
Read more >IAM Permissions For Functions - Serverless Framework
AWS Lambda functions need permissions to interact with other AWS services and resources in your account. These permissions are set via an AWS...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ywang9009gmail The solution is mentioned a few comments above:
The effect is that serverless will then use the
cfnRole
to run that custom resource lambda that checks and assigns to API Gateway the CloudWatch role you specified byrestApi.role
. If you already specify acfnRole
for limited-access deployments, that role must have a number of permissions assigned which were mentioned across various other issues. This is what policies I had to add to get it working (statements below extracted from role definition of MyCfnRole, I specified only stuff I had to add to be able to deploy once I enabled the logs):With this above config, I can confirm it works using the latest serverless v1.63, so I mentioned here in case somebody else hits it.
@medikoo @pmuens I played with this and I have to say I do not like the custom resource solution. At a minimum, it needs a dedicated documentation page to explain the effects of each setting, I had to wade through multiple github issues to figure out how it works and basically wasted a day. Admittedly, part of it discovering the missing permissions, given that CloudFormation is not always helpful. I have also ran into #6643, which in my case was likely due to lack of permissions, but the error was hidden away by the 10-retry logic in the custom resource which possibly got me the “too many requests errors”.
I understand that the CloudWatch log ARN is a global setting and you can’t add/remove it at will. What I would like to see then is for serverless not to try to set it at all. I am perfectly fine setting up a role at account level and assign it to API Gateway directly through CloudFormation resources (I do this in a separate “account setup” deployment). And I do not want the API deployment to create a custom resource just to double-check my ARN there, it looks like too much hassle to me and it forces me to grant additional permissions which are better left to the “account setup” part.
One simple way is to add an extra boolean setting to control this behavior. When false, assume it’s been assigned externally and do not create the custom resource (but: more settings = more confusion).
Another way is to just make this the default behavior and assume that when a role is given, it’s been also configured in API Gateway, so no need to use the custom resource at all. Document this (see above) and it’ll be fine. Figuring out all those permissions certainly takes more time than setting up the role via
resources
section.@medikoo
Can you help me understand why serverless is trying to create custom resources in the first place ?