Deployment failing after deleting API Gateway. How to recover?

After CORS preflight kept failing with “missing authentication token” i removed the api gateway manually via the aws console because changing the configuration in my serverless.yml file didn’t seem to change the Gateway configuration anymore.

Now deployment fails with " An error occurred while provisioning your stack: ApiGatewayDeployment1496768353300 - Invalid REST API identifier specified". I understand that this is an error caused by me, but can you hint me into the direction of how to recover from this?

1 Like
  1. Remove the http event triggers from every Lambda. If you have any other references to the API Gateway in your serverless.yml then remove those too. This should remove the API Gateway from your Cloud Formation template. You can check by looking at .serverless/cloudformation-template-update-stack.json
  2. Run sls deploy. This should remove the API Gateway from your Cloud Formation stack.
  3. Undo step 1
  4. Run sls deploy to create a new API Gateway.
7 Likes

thank you, that fixed it.

Just out of curiosity, would there be a way to recover from this without losing the api gateway subdomain?

Sadly no. The API Gateway ID is automatically generated by Amazon. If you were using a custom domain you could move that.

2 Likes

@buggy After I removed http and redeploy stack output still show ApiId and ServiceEndpoint.

You need to remove all references to it. Have a look at the CloudFormation output from Serverless. It should provide more information about what is using it.

@buggy I comment everything out and have only code below but for some reason it doesn’t update Cloudformation stack. Any idea? I deleted api gateway manually

service: cognito

provider:
name: aws
runtime: nodejs8.10
stage: {opt:stage, "dev"} region: {opt:region, “us-west-2”}
timeout: 30

Don’t look at your serverless.yml file. When you run serverless package it should create a folder .serverless with two cloudformation files. Look at the cloudformation-template-update-stack.json file for any references to your API.

@buggy here is my cloudformation-template-update-stack.json file and it’s only reference for s3bucket that deploy serverless file.
{
“AWSTemplateFormatVersion”: “2010-09-09”,
“Description”: “The AWS CloudFormation template for this Serverless application”,
“Resources”: {
“ServerlessDeploymentBucket”: {
“Type”: “AWS::S3::Bucket”,
“Properties”: {
“BucketEncryption”: {
“ServerSideEncryptionConfiguration”: [
{
“ServerSideEncryptionByDefault”: {
“SSEAlgorithm”: “AES256”
}
}
]
}
}
}
},
“Outputs”: {
“ServerlessDeploymentBucketName”: {
“Value”: {
“Ref”: “ServerlessDeploymentBucket”
}
}
}
}

and I still got same error with apiId

Are you 100% certain you’re updating the same stack?

Are you 100% certain the stack update is succeeding?

Beyond that I’m lost for why.

@buggy I tried to delete stack and it was not succeed either.

If you try deleting the stack in the AWS console it will typically fail because the deployment bucket has files in it. Remove those files plus files from any other S3 buckets you have and try again. On the second attempt at deleting it will often provide a list of resources that can’t be deleted and ask you if you want to leave them. Say yes and clean them up manually.

Thanks @buggy . Your answer was really helpful.

1 Like

Thank you for your help!!!