How to avoid AWS SAM rebuild and reupload a gradle function with unchanged code?

ぐ巨炮叔叔 提交于 2021-01-02 20:30:09

问题


I'm developing an application with micronaut using SAM CLI to deploy it on AWS Lambda. As I was including dependencies and developing new features, the function packages got bigger an bigger (now they are around 250MB). This makes deployment take a while.

On top of that every time I edit template.yaml and then run sam build && sam deploy to try a new configuration on S3, RDS, etc... I have to wait for gradle to build the function again (even though it's unchanged since the last deployment) and upload the whole package to S3.

As I'm trying to configure this application with many trials and errors on SAM, waiting for this process to complete just to get an error because of some misconfiguration is getting quite counterproductive.

Also my SAM s3 bcuket is at 10GB size after just a single day of work. This may get expensive on the long run.

Is there a way to avoid those gradle rebuilds and reuploads when teh function code is unchanged?


回答1:


If you are only updating the template.yml file, you could copy the new version to ./.aws-sam/build folder and then run sam deploy

$ cp template.yml ./.aws-sam/build/template.yml
$ sam deploy

If you are editing a lambda you could try to update the function code by itself (after you create it in the template and deploy of course). That can be done via the AWS CLI update-function-code command:

rm index.zip 
cd lambda 
zip –X –r ../index.zip *
cd .. 
aws lambda update-function-code --function-name MyLambdaFunction --zip-file fileb://index.zip

more info can be found here:

  • Alexa Blogs - Publishing Your Skill Code to Lambda via the Command Line Interface
  • AWS CLI Command Reference - lambda - update-function-code

my SAM s3 bcuket is at 10GB size

Heh. Yea start deleting stuff. Maybe you can write a script using aws s3?



来源:https://stackoverflow.com/questions/63156643/how-to-avoid-aws-sam-rebuild-and-reupload-a-gradle-function-with-unchanged-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!