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

Export xxxxx cannot be deleted error when removing Restful API routes #3655

Open
tchcxp opened this issue Feb 5, 2024 · 3 comments
Open

Comments

@tchcxp
Copy link

tchcxp commented Feb 5, 2024

Hi there,

I have a problem removing or updating routes in an imported API stack.

I use SST to build an API gateway and microservices in the backend. I love the live lambda, which saves heaps of time to build and debug lambda functions locally. 👍

The infrastructure is simple: there is one API stack file and a few service stack files, which use the exported API resource from the API stack.

The problem is when I remove or update any route in a service stack file, and deploy, I get an error message like: Export xxxxx cannot be deleted as it is in use by xxxxx.


Here is a quick demo to reproduce the issue:

  1. In the API stack api-stack.ts, I set up the Restful API gateway:
import { ApiGatewayV1Api } from 'sst/constructs'

 const api = new ApiGatewayV1Api(stack, 'Api', {
    cdk: {
      restApi: {
        restApiName: 'demo-api',
      },
    },
  })

return { api }
  1. In the Demo service stack file demo-service.ts, I added 2 routes to the API gateway:
import { use, StackContext } from 'sst/constructs'
import { ApiStack } from './api-gateway'

export function DemoServiceStack({ stack }: StackContext) {
  const { api } = use(ApiStack)
  api.addRoutes(stack, {
    'GET /demo-path':  'packages/functions/v1/demo-service/get.handler',
    'POST /demo-path':  'packages/functions/v1/demo-service/post.handler'
    })
})
  1. In the sst.config.ts file, I added stacks:
import { SSTConfig } from 'sst'
import { ApiStack } from './stacks/api-gateway'
import { DemoServiceStack } from './stacks/demo-service'

export default {
  config(_input) {
    ...
  },
   stacks(app) {
    app
      .stack(ApiStack)
      .stackk(DemoServiceStace)
    }
}

Now I remove a route (e.g. 'GET /demo-path': 'packages/functions/v1/demo-service/get.handler', in the 2nd file above), I receive the error message below:

demo-service: Export demo-service:ExportsOutputFnGetAttLambdaGETv1xxxxxxxxxxxxxxCD5D cannot be deleted as it is in use by api-gateway

I understand why this error message happens, but I guess it was resolved when I found automatic export injection.

I was thinking about removing the reference, in this case, the api resource; however, I still need the other routes in the same file.

Please let me know if there is any setting I was not aware of or if there is a workaround that can fix this issue. I do love using SST to build serverless applications but not confident about using it in production in this case because I cannot delete or update a route in the API.

Thanks,

@jayair
Copy link
Contributor

jayair commented Feb 7, 2024

Yeah this is painful and not intuitive. It's partly why we are moving away from CDK and CloudFormation for our next version.

This specific issue I talk about it here: https://sst.dev/blog/moving-away-from-cdk.html#3-export-in-use

@tchcxp
Copy link
Author

tchcxp commented Apr 3, 2024

Yeah this is painful and not intuitive. It's partly why we are moving away from CDK and CloudFormation for our next version.

This specific issue I talk about it here: https://sst.dev/blog/moving-away-from-cdk.html#3-export-in-use

Thanks, @jayair Is there any timeline for migrating the new version that not using CDK?

@jayair
Copy link
Contributor

jayair commented Apr 3, 2024

Ion is live, if you have a new app I'd recommend trying it. But we are working on getting it to a point where we can help with migrations.

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

No branches or pull requests

2 participants