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

API Key length causing deployment to fail #7628

Open
revgum opened this issue Apr 27, 2020 · 11 comments
Open

API Key length causing deployment to fail #7628

revgum opened this issue Apr 27, 2020 · 11 comments

Comments

@revgum
Copy link

revgum commented Apr 27, 2020

Bug Report

Description

When a specified API Key has fewer than 20 characters, deployment fails without any evidence as to why. I used to AWS Console to try to create the key manually and saw the key length requirement show up there. The error provided on the AWS Console is API Key value should be at least 20 characters.

  1. What did you do?
    Set an API Key value having fewer than 20 characters in configuration.

  2. What happened?
    CloudFormation repeatedly failed to create ApiGatewayApiKey1 and rolled back deployment with no error details.

  3. What should've happened?
    Serverless should have prevented deployment by validating the api key length.

  4. What's the content of your serverless.yml file?

provider:
  apiKeys:
    - name: ${self:service.name}-api-key
      value: tooshort 
  1. What's the output you get when you use the SLS_DEBUG=* environment variable (e.g. SLS_DEBUG=* serverless deploy)

Template validation passes, typical resource creation happens and eventually:
CloudFormation - CREATE_FAILED - AWS::ApiGateway::ApiKey - ApiGatewayApiKey1 followed by all of the resource deletes.

Similar or dependent issues:

@medikoo
Copy link
Contributor

medikoo commented Apr 28, 2020

@revgum thanks for report

CloudFormation repeatedly failed to create ApiGatewayApiKey1 and rolled back deployment with no error details.

I just issued such test deployment and output was:

Serverless Error ---------------------------------------
 
  An error occurred: ApiGatewayApiKey1 - API Key value should be at least 20 characters (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 3df4aed1-4343-4cca-9e29-f79c90c37a08).

Are you relying on latest version of a Framework?

@revgum
Copy link
Author

revgum commented Apr 28, 2020

I was using the latest, however, my actual apiKeys value was coming from an ${env:API_KEY}. That wouldn't make sense why I don't see the same error you're seeing. Any ideas?

@medikoo
Copy link
Contributor

medikoo commented Apr 28, 2020

That wouldn't make sense why I don't see the same error you're seeing. Any ideas?

What exactly ends in generated CloudFormation template?

@revgum
Copy link
Author

revgum commented Apr 28, 2020

It looks legit;

    "ApiGatewayApiKey1": {
      "Type": "AWS::ApiGateway::ApiKey",
      "Properties": {
        "Enabled": true,
        "Name": "abc-development-api-key",
        "Value": "abc-123-test",
        "StageKeys": [
          {
            "RestApiId": {
              "Ref": "ApiGatewayRestApi"
            },
            "StageName": "development"
          }
        ]
      },
      "DependsOn": "ApiGatewayDeployment123456789012345"
    },

...
The CREATE_FAILED followed by a bunch of DELETE_COMPLETE and finally the only error from Serverless is:

...
CloudFormation - DELETE_COMPLETE - AWS::CloudFormation::Stack - abc-development
Serverless: Stack create finished...
Serverless: Invoke aws:info
Serverless: [AWS cloudformation 400 0.475s 0 retries] describeStacks({ StackName: 'abc-development' })

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

  ServerlessError: Stack with id abc-development does not exist
      at /Users/joshgum/Documents/code/abc/node_modules/serverless/lib/plugins/aws/provider/awsProvider.js:331:27
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              12.16.1
     Framework Version:         1.68.0
     Plugin Version:            3.6.8
     SDK Version:               2.3.0
     Components Version:        2.30.2

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@medikoo
Copy link
Contributor

medikoo commented Apr 28, 2020

The CREATE_FAILED followed by a bunch of DELETE_COMPLETE and finally the only error from Serverless is:

This error seems related to some other issue with your configuration, and that's why the API key error doesn't surface for you.

It's hard for me to state what can be wrong not know your full configuration, and not having full sls deploy output (with SLS_DEBUG=*)

@revgum
Copy link
Author

revgum commented May 1, 2020

I think the underlying problem is that there are resources being created that depend on the API key and they fail being created at the same time the API key fails to be created.. the API key length error gets swallowed up by these circumstances and never surfaces in a meaningful way. The stack rollback happens, and you are left not knowing why it really failed.

When I deploy an updated lambda affecting the API Gateway along with the value of the API key to under 20 characters I get the errors I've left in the issue ticket already. The only things you don't see are the lambdas each having CREATE_FAILED, then all of the changes being deleted, the stack rolling back and the bad error indicating the stack doesn't exist even though it does.

I hope this helps!

@revgum
Copy link
Author

revgum commented May 1, 2020

I wanted to add that I tried a few scenarios;

  • Deploy with a custom named API Key and a value < 20 characters

    • The error gets swallowed by Serverless and I only see the aforementioned errors.
  • Deploy with an automatically generated name for API Key and a value < 20 characters

    • You will see the error from AWS stating that the key length fails

@medikoo
Copy link
Contributor

medikoo commented May 4, 2020

The only things you don't see are the lambdas each having CREATE_FAILED, then all of the changes being deleted, the stack rolling back and the bad error indicating the stack doesn't exist even though it does.

@revgum thanks for clarification. This looks very familiar to: #7635 - it appears that it's the source of an issue that hides real error from you

@AhmedFat7y
Copy link
Contributor

@revgum Could you provide list of events for that failed stack? (at least the events statuses without reosuces ids).

Serverless checks for the stack progress/success/failure through the events provided by describe stack-events. So, it might be helpful if you could provide list of events for a failed stack because I get a normal error message when I try to deploy a stack with an error in deployment stage.

@arash-bizcover
Copy link

This is 5th time in last year, I'm searching whole Github. how to explicitly set value of API key on this Serverless lambda thing😰
It just doesn't work

@medikoo
Copy link
Contributor

medikoo commented Sep 16, 2020

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

Successfully merging a pull request may close this issue.

4 participants