Aws-sam-cli: [Question] How override remote changes with sam deploy?

Created on 8 Apr 2019  路  5Comments  路  Source: aws/aws-sam-cli

I'm currently using SAM to describe my serverless REST API so I have a collection of lambda functions attach to an ApiGateway route with all properties describe in template files.

I have a lot of lambdas / routes (so splitted in different templates files / nested app) and it take some times to update. So for debugging I use the AWS Web Console (for example editing lambdas) and when it was tested I impact my template file.

The problem is when I deploy the app using SAM all lambdas that I modified directly via the Web Console are not updated. (code, mapping functions, params, ...)

Finally I ask how can I override remote changes when I using SAM deploy?

Thanks in advance for your future response.

typquestion

All 5 comments

@Hideman85 This is a limitation of CloudFormation. CloudFormation holds it's own view of the template (and therefore the resources it creates for you). Editing resources outside of the template causes drift. Using the CloudFormation Drift Detection might be what you are after.

Generally, I do not recommend these sort of out-of-band changes (aws cli, console, etc). Ideally, you want to make changes to your template and make CloudFormation the one that mutates your Resources, especially in production. I know there are cases to do these manually changes but you should be careful as you run the risk of a new deployment changes configurations back to what is defined in CloudFormation. So even if you are manually mutating, you should always be updating CloudFormation and the source code for lambda functions.

Are there reasons you are using the Console to edit code for testing rather than using SAM CLI?

The only reason it's for debugging in the dev stack. Because of deployment (with the API splitted in some nested app due to the limits of 200 resources per template) is too long (卤5mins) for debugging it's really quite speed to directly update lambda code via lambda web console.

I also have issue with cross ref when I update my stack.
Stack layout:

Root stack
---> Database stack
---> Api stack
-------> RestApi description with inline generated swagger
-------> LambdaFunc stack part1
-------> LambdaFunc stack part2
-------> LambdaPerm stack part1

When I create the stack and delete the stack the process is correct

Root -> Database
     -> Api
          -> LambdaFunc stack part1
          -> LambdaFunc stack part2
          -> RestApi
          -> LambdaPerm stack part1

But when I update lambda code (for example in LambdaFunc stack part1) cloudformation try to update the lambda directly without remove attached perms before so cause an error & rollback.

Sorry for asking a second question in the same thread but maybe I don't use the correct structure and use the good one can have an impact on the time for deploying.

You can test or run functions locally through sam local invoke|start-api|start-lambda. We don't yet support nested stacks but this doesn't stop you from invoke the function in a sub stack (pass the nested template into the command through -t). This allows us to test locally and avoid the long deploy test cycle.

Yes it could be a solution but you said that sam don't support nested stack but in sam we can use AWS::Serverless::Application so if I use sam local start-api can I have my full api run locally? (I need to try)

@Hideman85 You can still pass the a single templates into the command (one of the nested templates) and invoke. So you should still have the ability to test this locally regardless.

If you want to test in the console, you will need to use the Drift Detection feature of CloudFormation to see what changes were made or manually do this to the template/code you are editing. You can still test individual templates in SAM CLI by passing one of the nest templates into the sam local commands with -t.

Closing, since the initial question was answered.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jpbarto picture jpbarto  路  4Comments

red8888 picture red8888  路  3Comments

cvuijst picture cvuijst  路  3Comments

joekiller picture joekiller  路  4Comments

dschu-lab picture dschu-lab  路  3Comments