Closed ozbillwang closed 7 years ago
@ozbillwang Thanks for the report.
This might be an issue with the ANY
method for endpoint proxies supporting any HTTP method.
All other parts of the settings path /profile/ANY/logging/loglevel
match the pattern /{resourcePath}/{httpMethod}/logging/loglevel
mentioned in the error text.
Maybe AWS expects that the plugin translates ANY to the complete set of allowed methods that are covered by ANY.
Can you do a double check and specify the setting on function level, for just a function that does not have ANY endpoints and see if it then works? If yes, the ANY support has to be fixed in the plugin.
yes, the problem is gone, after rename any
to other method.
Then I got this error:
An error occurred: ApiGatewayStage - CloudWatch Logs role ARN must be set in account settings to enable logging.
I added a role with this permission:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:*"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
and
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "apigateway.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
I still got same error. So what role should I create, and can you show some codes for me?
@ozbillwang You have to create a role as mentioned here: https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-cloudwatch-logs/ with the AmazonAPIGatewayPushToCloudWatchLogs policy attached.
And then in the API Gateway console at the bottom there is "Settings". Enter the role you created and it should work. The role configuration in API Gateway is an account setting and applies to all APIs. This will enable the general use of the API logging and afterwards the deploy should go through.
If there is already a role assigned to API Gateway, you should look that up in IAM and just add the missing policy.
... and thank you for the test. Then this bug has to be fixed to allow and support the any special method.
@HyperBrain
After added the role manually from API Gateway console -> setting, it works now. Thanks a lot
So my code to add role directly in serverless.yml
doesn't work with cloudwatch logs
provider:
name: aws
runtime: nodejs6.10
role: arn:aws:iam::12345678:role/serverless-lambda-role
I think you do not need the role in your serverless.yml
or do you not want to use the role that is generated by Serverless?
Sure. I just realised the role serverless-lambda-role
is a global role which need be setup separately and manually and will be applied to all api gateways.
In my first thinking, I'd like to manage this role in serverless.yml
. So I can define the options for different gateways.
@ozbillwang Can you check with the attached PR, if ANY is supported correctly now?
Thanks @HyperBrain
How to install this un-released version?
Just use "serverless-aws-alias": "github:HyperBrain/serverless-aws-alias#support-any-in-stage-config"
in your package.json. It will then install the branch directly from GitHub.
Hmmm... this sounds a bit unrelated as I only changed the method name in the method settings.
Can you check if the ....update-alias.json
template created in the .serverless
folder contains this resource?
I did a check with the serverless-aws-alis example and used logging for one ANY endpoint:
functions:
testfct1:
description: 'Echo function echoes alias'
handler: handlers/testfct1/handler.handle
events:
- http:
method: ANY
path: /func1
aliasStage:
loggingLevel: INFO
and did not run into any issue with the deployment resource - but encountered that setting it to *
is not the solution, but I have to set it for all methods explicitly in this case. I fixed that and it worked:
I tested several times, then build a new serverless docker image (svls/serverless:1.24.1
), remove folder node_modules
and .serverless
, do the deployment in container, more than my laptop directly. So the whole environment is isolated.
But still get this error.
Error --------------------------------------------------
The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayDeployment1511310010733] in the Resources block of the template
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
Error: The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayDeployment1511310010733] in the Resources block of the template
at provider.request.catch (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/plugins/aws/deploy/lib/validateTemplate.js:25:13)
From previous event:
at AwsDeploy.validateTemplate (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/plugins/aws/deploy/lib/validateTemplate.js:20:12)
From previous event:
at AwsDeploy.BbPromise.bind.then (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/plugins/aws/deploy/index.js:117:39)
From previous event:
at Object.aws:deploy:deploy:validateTemplate [as hook] (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/plugins/aws/deploy/index.js:113:10)
at BbPromise.reduce (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:366:55)
From previous event:
at PluginManager.invoke (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:366:22)
at PluginManager.spawn (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:384:17)
at AwsDeploy.BbPromise.bind.then (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/plugins/aws/deploy/index.js:91:48)
From previous event:
at Object.deploy:deploy [as hook] (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/plugins/aws/deploy/index.js:87:10)
at BbPromise.reduce (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:366:55)
From previous event:
at PluginManager.invoke (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:366:22)
at PluginManager.run (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/classes/PluginManager.js:397:17)
at variables.populateService.then (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/Serverless.js:104:33)
at runCallback (timers.js:781:20)
at tryOnImmediate (timers.js:743:5)
at processImmediate [as _immediateCallback] (timers.js:714:5)
From previous event:
at Serverless.run (/usr/local/share/.config/yarn/global/node_modules/serverless/lib/Serverless.js:91:74)
at serverless.init.then (/usr/local/share/.config/yarn/global/node_modules/serverless/bin/serverless:42:50)
at <anonymous>
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless
Your Environment Information -----------------------------
OS: linux
Node Version: 8.4.0
Serverless Version: 1.24.1
The steps are:
$ docker run --rm -it -v $(pwd):/opt/app -v ~/.aws:/root/.aws -v ~/.ssh:/root/.ssh svls/serverless:1.24.1 bash
bash-4.3# sls deploy // deployment is fine.
bash-4.3# vi package.json // add new package serverless-aws-alias
bash-4.3# npm install
bash-4.3# vi serverless.yml // add plugins and aliasStage
bash-4.3# sls deploy
Wait, in fact, I get the same error for your current latest release v1.5.0 as well. So that's not your PR issue.
Did you test with latest serverless version?
I test in 1.23.0 container (svls/serverless:1.23.0
), still get the same error. So maybe that's my code issue.
But why there is no deploy issue, if I clean all alias setting?
@HyperBrain
It works with another serverless stack with any
method, a simple serverless.yml
So my understanding is, the problem for any
method is fixed. There are something else in my project which I need time to dig it out.
@ozbillwang I have the same problem with my project and got the same error message
"The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayDeployment1511324460661] in the Resources block of the template"
I managed to fix that by removing another plugin "serverless-domain-manager" from my serverless.yml file. Do you use that plugin too? At this stage, I am not sure if the problem is with "serverless-domain-manager" or "serverless-aws-alias".
Thanks @demsey2 .
I didn't use any other plugins in this project currently. serverless-aws-alias
is the only plugin I try to active apigateway access logs.
@demsey2 For you it might be the order of the plugins in the serverless.yml
. I'm quite sure that the alias plugin must be the last one in the list, because it needs to access the final generated CF template, without any other plugins modifying it afterwards. Maybe it would be worth having a look at the domain plugin's sources to see if and how it modifies the template.
@ozbillwang ... and yes, we use SLS 1.24.1 at work (I use these projects to find out about incompatibilities early đŸ˜„ ). But, do you have some custom resources defined in your Resources
section in serverless.yml
that depend on the gateway deployment?
Released with 1.5.1
Add the plugin in my exist serverless.yml
But got below error , when deploy: