简体   繁体   English

如何强制 AWS SAM CLI 检测更改?

[英]How to force AWS SAM CLI to detect changes?

Amazon's SAM CLI does not pick up changes without rebuilding. Amazon 的 SAM CLI 不会在不重建的情况下获取更改。 The documentation SOUNDS like I should not have to start/rebuild/restart every time I make a change to a function. In fact, issuing the sam local start-api command provides the following message...文档听起来像我不必每次更改 function 时都必须启动/重建/重新启动。实际上,发出sam local start-api命令会提供以下消息...

You do not need to restart/reload SAM CLI while working on your 
functions, changes will be reflected instantly/automatically.  
You only need to restart SAM CLI if you update your AWS SAM template.  

However, changes are not detected automatically.但是,不会自动检测到更改。 So, changing this ...所以,改变这个......

const test = async (event, context) => {
  const body = JSON.parse(event.body || {});
  return toResponse(body);
};

... to this... ……对这个……

const test = async (event, context) => {
  const body = JSON.parse(event.body || {});
  body.date = new Date();
  return toResponse(body);
};

... should cause the body variable to include a date property. ...应该导致body变量包含date属性。 Unfortunately, the only way to force this is to stop ( CTRL+C ), and then...不幸的是,强制这样做的唯一方法是停止( CTRL+C ),然后......

sam build
sam local start-api

This is torture as the sam build takes almost a minute on a 32GB i7 MacBook Pro.这是一种折磨,因为sam build在 32GB i7 MacBook Pro 上需要将近一分钟的时间。

To solve the problem of time to build, rather than building the whole template file just build the Lambda that you have made changes to.要解决构建时间问题,而不是构建整个模板文件,只需构建您已更改的 Lambda。

sam build <FunctionName>
sam local start-api

The should be the same as the one you specified in the template.yaml.应该与您在模板中指定的相同。yaml。

I was able to get this to work by NOT running sam build and instead just run sam local start-api .我能够通过运行sam build而只是运行sam local start-api来让它工作。 If you have run sam build delete the .aws-sam folder, then run sam local start-api again, or sam local invoke... .如果您已运行sam build删除.aws-sam文件夹,然后再次运行sam local start-api ,或sam local invoke... That should hot-load the latest code each time!那应该每次都热加载最新的代码!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM