Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid method setting path #80

Closed
ozbillwang opened this issue Nov 16, 2017 · 19 comments
Closed

Invalid method setting path #80

ozbillwang opened this issue Nov 16, 2017 · 19 comments
Labels
Milestone

Comments

@ozbillwang
Copy link

Add the plugin in my exist serverless.yml

plugins:
  - serverless-aws-alias

provider:
  name: aws
  runtime: nodejs6.10
  aliasStage:
    loggingLevel: "INFO"
    dataTraceEnabled: true

But got below error , when deploy:


Serverless: Checking Stack update progress...
........^@...................
Serverless: Operation failed!

  Serverless Error ---------------------------------------

  An error occurred: ApiGatewayStage - Invalid method setting path: /profile/ANY/logging/loglevel. Must be one of: [/deploymentId, /description, /cacheClusterEnabled, /cacheClusterSize, /clientCertificateId, /accesslogging, /accesslogging/destination, /accesslogging/format, /{resourcePath}/{httpMethod}/metrics/enabled, /{resourcePath}/{httpMethod}/logging/dataTrace, /{resourcePath}/{httpMethod}/logging/loglevel, /{resourcePath}/{httpMethod}/throttling/burstLimit/{resourcePath}/{httpMethod}/throttling/rateLimit/{resourcePath}/{httpMethod}/caching/ttlInSeconds, /{resourcePath}/{httpMethod}/caching/enabled, /{resourcePath}/{httpMethod}/caching/dataEncrypted, /{resourcePath}/{httpMethod}/caching/requireAuthorizationForCacheControl, /{resourcePath}/{httpMethod}/caching/unauthorizedCacheControlHeaderStrategy, /*/*/metrics/enabled, /*/*/logging/dataTrace, /*/*/logging/loglevel, /*/*/throttling/burstLimit /*/*/throttling/rateLimit /*/*/caching/ttlInSeconds, /*/*/caching/enabled, /*/*/caching/dataEncrypted, /*/*/caching/requireAuthorizationForCa.

  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:           6.11.3
     Serverless Version:     1.24.1

@HyperBrain
Copy link
Member

@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.

@HyperBrain HyperBrain added the bug label Nov 16, 2017
@ozbillwang
Copy link
Author

ozbillwang commented Nov 16, 2017

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?

@HyperBrain
Copy link
Member

HyperBrain commented Nov 16, 2017

@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.

@HyperBrain
Copy link
Member

... and thank you for the test. Then this bug has to be fixed to allow and support the any special method.

@ozbillwang
Copy link
Author

ozbillwang commented Nov 17, 2017

@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

@HyperBrain
Copy link
Member

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?

@ozbillwang
Copy link
Author

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.

@HyperBrain
Copy link
Member

@ozbillwang Can you check with the attached PR, if ANY is supported correctly now?

@HyperBrain HyperBrain added this to the 1.5.1 milestone Nov 21, 2017
@ozbillwang
Copy link
Author

Thanks @HyperBrain

How to install this un-released version?

@HyperBrain
Copy link
Member

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.

@HyperBrain
Copy link
Member

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?

@HyperBrain
Copy link
Member

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:
image

@ozbillwang
Copy link
Author

ozbillwang commented Nov 21, 2017

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

Updates:

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?

update #2

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?

@ozbillwang
Copy link
Author

@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.

@demsey2
Copy link

demsey2 commented Nov 22, 2017

@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".

@ozbillwang
Copy link
Author

ozbillwang commented Nov 22, 2017

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.

@HyperBrain
Copy link
Member

@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.

@HyperBrain
Copy link
Member

@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?

@HyperBrain
Copy link
Member

Released with 1.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants