0

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.

1 Answer 1

3

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 subsequent sam 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.

Sign up to request clarification or add additional context in comments.

4 Comments

Detecting which resources need updating is based on the properties, such as CodeUri, right? The problem with that approach, is that other microservices would have to be built and their hashes checked again, and this is what I'm trying to avoid.
have to be built and their hashes checked would you want to do this manually??? running sam build && sam deploy should only take a few minutes.
While the sam cli is the aws recommended way of doing this, sam deploy is painfully slow for active development which I'm assuming why many (like myself) would like an alternative for quick lambda changes during active development (using local-api isn't always a solution, for me I have sqs and other aws infrastructure so I need to actually deploy the lambdas for many minor changes during active dev)
As a followup to my previous comment, once you deploy once during aws sam, you can use the lamba "update function code" method to update just the lambda code for small changes without the need for a full redeploy. I found this example and modified it a bit for my purposes since I'm not using node/webpack: dev.to/spalladino/…

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.