8

Recently I use Serverless framework do create/deploy AWS lambda function / API gateway. It's a very cool way to deploy Lambda/API but I don't know how to apply it to existing AWS lambdas / APIs.

Is there any way to do it without drop the existing one then re-creating using serverless because i have dozens of existing lambda functions and apis.

3
  • maybe this might help? confluence.atlassian.com/bitbucket/…
    – mph85
    Commented Jun 14, 2019 at 3:35
  • 1
    thank you @mph85 but that ins't the solution i'm looking for
    – DonerKebab
    Commented Jun 14, 2019 at 6:40
  • np np, I'm misunderstanding then, what would prevent you from plugging in your existing Lambda function into AWS Lambda and letting the service take care of compiling it and all that?
    – mph85
    Commented Jun 14, 2019 at 6:42

2 Answers 2

4

https://www.serverless.com/framework/docs/providers/aws/events/apigateway/#share-api-gateway-and-api-resources

As your application grows, you will likely need to break it out into multiple, smaller services. By default, each Serverless project generates a new API Gateway. However, you can share the same API Gateway between multiple projects by referencing its REST API ID and Root Resource ID in serverless.yml as follows:

service: service-name
provider:
  name: aws
  apiGateway:
    restApiId: xxxxxxxxxx # REST API resource ID. Default is generated by the framework
    restApiRootResourceId: xxxxxxxxxx # Root resource, represent as / path
    websocketApiId: xxxxxxxxxx # Websocket API resource ID. Default is generated by the framework
    description: Some Description # optional - description of deployment history

functions: ...
2
  • but then you would have to create the api gateway with one serverless service, and then once created, go back and update your serverless file to insert that id. I know it's possible but it is kind of clunky right? there should be other way, or I do think the best is to create the apigateway outside of serverless. Commented Nov 4, 2021 at 4:30
  • 1
    You can use Terraform to control critical infrastructure, like the API Gateway, the allowed API Keys, usage plans, etc. see here By storing the corresponding restAPIId, restApiRootResourceId, websocktApiId in parameter store, there is no need to copy these variables separately to each serverless file (see ssm variables in serverless) Commented Mar 20, 2023 at 10:13
-1

No. You can reuse the lambda functions by pointing to the specific ARN's of those functions within Serverless.yml, but there is currently no way to "replace" the API Gateway component without manual intervention and re-creation using Serverless.

The upside is, it should be relatively straightforward and easy to do unless you use features in AWS API Gateway currently not supported by the Serverless framework.

2
  • But what if I have a complext apigateway settings ? how can I get the serverless.template EVents section for that api ?
    – Royi Namir
    Commented Feb 15, 2020 at 14:12
  • @RoyiNamir you should check Cloudformation template syntax. Serverless is basically replicating those options whereas possible.
    – Cninroh
    Commented Aug 7, 2020 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.