I am using CloudFormation with SAM to deploy a stack which contains:
- S3 Bucket
- Cognito
AWS::Serverless::Api
AWS::Serverless::Function
(authorizers + microservices,Type: Api
and endpoints of the API Gateway)- Log Groups
To deploy my stack, I first run aws cloudformation package
to package the lambda and then run aws cloudformation deploy
to deploy the generated stack. This is working.
My goal now is to be able to update a microservice without deploying the entire stack (not building authorizers and other microservices), similar to serverless deploy function
in the Serverless framework. This should preferably be one reusable template that uses a macro or just replaces text in the file.
The problem I am facing with this:
- Running
aws lambda update-function-code
requires the lambda to be redeployed - To redeploy the lambda I have to declare
AWS::Serverless::Function
. For the function to be part of the API Gateway,AWS::Serverless::Api
must be declared as well. - Declaring
AWS::Serverless::Api
requires all the other functions to be defined or they will be removed from the API Gateway.
I feel like I am stuck here and have not found other options of achieving my goal.
Since you're using SAM, I'd recommend deploying and updating your application using the sam cli commands.
You can run
sam build
sam package
sam deploy
When you run
sam deploy
, it deploys your application, but all subsequentsam deploy
commands will update your existing cloudformation stack with only the appropriate resources that need updating.If you opt for keeping with the standard Cloudformation cli commands, you could use the
aws cloudformation update-stack
command so that you're not re-deploying an entire new stack.