如何避免 AWS SAM 重建并重新上传代码不变的 gradle 函数? [英] How to avoid AWS SAM rebuild and reupload a gradle function with unchanged code?

查看:77
本文介绍了如何避免 AWS SAM 重建并重新上传代码不变的 gradle 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 micronaut 开发一个应用程序,使用 SAM CLI 将其部署在 AWS Lambda 上.当我包含依赖项和开发新功能时,函数包变得越来越大(现在它们大约 250MB).这使得部署需要一段时间.

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.

最重要的是每次我编辑 template.yaml 然后运行 ​​sam build &&sam deploy 在 S3、RDS 等上尝试新配置...我必须等待 gradle 再次构建该函数(即使自上次部署以来它没有改变)并将整个包上传到 S3.

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.

当我尝试在 SAM 上通过多次试验和错误来配置这个应用程序时,等待这个过程完成只是为了因为一些错误配置而出现错误会适得其反.

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.

此外,我的 SAM s3 bcuket 在一天工作后的大小为 10GB.从长远来看,这可能会变得昂贵.

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

在函数代码不变的情况下,有没有办法避免那些gradle重建和重新上传?

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

推荐答案

如果您只更新 template.yml 文件,您可以将新版本复制到 ./.aws-sam/build 文件夹 然后运行 ​​sam deploy

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

如果您正在编辑 lambda,您可以尝试自行更新函数代码(当然是在模板中创建并部署之后).这可以通过 AWS CLI update-功能代码命令:

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:

我的 SAM s3 bcuket 大小为 10GB

my SAM s3 bcuket is at 10GB size

呵呵.是的,开始删除东西.也许您可以使用 aws s3?

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

这篇关于如何避免 AWS SAM 重建并重新上传代码不变的 gradle 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆