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

Serverless framework deleting the already existing resource on sls deploy #6810

Closed
jayanthck opened this issue Oct 9, 2019 · 2 comments
Closed

Comments

@jayanthck
Copy link

jayanthck commented Oct 9, 2019

serverless.yml.zip

Bug Report

deploying the serverless template when a resource already exists, it is deleting the resource instead of updating it or not doing any changes

Description

  1. What did you do?
    First I ran the sls deploy with out this property
    restApiResources:
    'test': hy1234
    and after this, I added the above property and ran sls deploy again

  2. What happened?
    ApiGatewayResourceTest is getting deleted

  3. What should've happened?
    Instead of deleting the resource ApiGatewayResourceTest, it should have updated it or left the resource unchanged

  4. What's the content of your serverless.yml file?
    attached the serverless.yml.zip
    service: serverlessfunction
    provider:
    name: aws
    region: 'eu-central-1'
    stage: stage
    runtime: nodejs10.x
    apiGateway:
    restApiId: '6k12345678'
    restApiRootResourceId: '6j12345678'
    restApiResources:
    'test': hy1234
    functions:
    hello:
    handler: handler.hello
    events:

    • http:
      path: 'test'
      method: post
      cors: true
  5. What's the output you get when you use the SLS_DEBUG=* environment variable (e.g. SLS_DEBUG=* serverless deploy)
    ApiGatewayResourceTest is getting deleted
    and there is new AGW deployment

@tinexw
Copy link
Contributor

tinexw commented Nov 1, 2019

Hi, I'm having the same issue. I have created a minimal example that reproduces the issue: https://github.com/tinexw/serverless-issue-6810

The example performs the following steps:

  • Deploy one HTTP endpoint /bar.
  • Deploy another HTTP endpoint /foo.
  • Deploy the first endpoint /bar again. This is where the bug occurs. The endpoint is deleted.
  • Deploy the first endpoint /bar yet again. This will create the endpoint again.

In all steps the apiGateway.restApiResources property always contains all existing resources e.g. when deploying /bar for the 2nd time, the config file contains an entry like

apiGateway:
  restApiResources:
    bar: e7frq7
    foo: t8np6h

This seems to be the cause of the issue. If I remove the existing resource from the list, the issue does not appear. I found a unit test for the corresponding part of the code that seems to expect exactly this behavior:

it('should not create any child resources if all resources exists', () => {

Please find the complete output of the minimal example below:

==== Deploying bar - 1st run ====
-- apiGateway.restApiResources --
---------------------------------
------ Available resources ------
/	4gyxjxwh0m
/bar	e7frq7
---------------------------------
=================================

========= Deploying foo =========
-- apiGateway.restApiResources --
bar: e7frq7
---------------------------------
------ Available resources ------
/	4gyxjxwh0m
/bar	e7frq7
/foo	t8np6h
---------------------------------
=================================

==== Deploying bar - 2nd run ====
-- apiGateway.restApiResources --
bar: e7frq7
foo: t8np6h
---------------------------------
------ Available resources ------
/	4gyxjxwh0m
/foo	t8np6h              <----- only foo available, bar was removed!
---------------------------------
=================================

==== Deploying bar - 3rd run ====
-- apiGateway.restApiResources --
foo: t8np6h           
---------------------------------
------ Available resources ------
/	4gyxjxwh0m
/foo	t8np6h
/bar	xcput9              <----- bar is back (with a new id)
---------------------------------
=================================

@medikoo
Copy link
Contributor

medikoo commented Dec 3, 2021

@jayanthck by declaring that you wish to setup configured endpoints on externally configured API Gateway resource, you've also declared that you don't need API Gateway resource that was created with a stack.

In CloudFormation it is assumed that stack is the only owner of created resources, therefore if it's removed from CF as not needed, it is also deleted.

So what you observed it's not a bug, it's the nature of the CF design.

Closing, as I believe we can't do much about that

@medikoo medikoo closed this as completed Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants