Serverless team are still working to add this feature in core service directly (https://github.com/serverless/serverless/issues/4461). If you need enable cloud watch logs for API Gateway using Serverless now, please follow this document.
Create a new IAM role (for example, apigateway-cloudwatch-logs-role) with trust policy apigateway.amazonaws.com
Attach aws exist policy AmazonAPIGatewayPushToCloudWatchLogs to this role
Record this IAM role’s ARN
Add this iam role’s arn to apigatewa-> settings -> CloudWatch log role ARN*
These are manual tasks.
With this setup, all your api gateways are ready for generating access logs in Cloudwatch. This is a global setting for API Gateway, that’s the reason why it can’t be managed by serverless framework (in serverless.yml)
Notes: Don’t define Provider -> role with the new role you created above, because the Provider:role used in serverless.yml is for lambda function, not for api gateway. If you do that, you lost all permissions in lambda functions.
Install the plugin serverless-plugin-stage-variables and run sls deploy
Trigger several api gateway access, you should see the access logs in cloudwatch now.
Serverless Error ---------------------------------------
An error occurred: ApiGatewayStage - 1 validation error detected: Value null at 'createStageInput.deploymentId' failed to satisfy constraint: Member must not be null (Service: AmazonApiGateway; Status Code: 400; Error Code: ValidationException; Request ID: 270600b3-97f0-11e8-b138-2f94522f87b3).
Wondering where I can get this deployment ID from?
An error occurred: ApiGatewayStage - qa already exists.
I am adding logging to an existing deployment, so the environment/stage does already exist, but I am unsure how to let it add to that environment/stage.
I can’t enable CloudWatch logs for API Gateway. It doesn’t give error but when I check serverless logs I can see somehow logLevel is OFF and tracingEnabled is false.
Does anyone have an idea why I can’t enable CloudWatch logs? By the way I have already set a CloudWatch log role ARN in API Gateway settings. I just need to enable logging for API Gateway.
My sls version is 1.44.1 as well. I have added the following key under provider:
logs:
restApi: true
However the result is still the same and logs have the following lines as well which I think that it means somehow logging settings are OFF although I say resAPI is true.
Is there a way I can create API gateway resource with CloudFormation script rather than serverless creation? Because even if I manage to enable logs, I need to enable caching and access logging as well.
I have tried with 1.41.1 and it didn’t work and then I have installed the latest version(1.45.1) and tried again. It didn’t work and it gave the following error message:
Rest API could not be resolved. This might be casued by a custom API Gateway setup. With you current setup stage specific configurations such as tracing, logs and tags are not supportedPlease update your configuration or open up an issue if you feel that there's a way to support your setup.
By the way there is a spelling mistake in the error message; casued should be replaced with caused.
I have deleted the whole stack and tried again and finally it worked with the following key: