[英]Serverless Framework: how to deploy with CloudFormation?
I am new to the serverless framework. 我是无服务器框架的新手。 Well, at least to the latest version, which depends heavily on CloudFormation. 好吧,至少到最新版本,这在很大程度上取决于CloudFormation。
I installed the framework globally on my computer using: 我使用以下方法在我的计算机上全局安装框架
npm install -g serverless
I then created a service using: 然后,我创建了一个服务:
serverless create --template aws-nodejs --path myService
Finally, I ran: 最后,我跑了:
serverless deploy
Everything seems to deploy normally, it shows no error in the terminal. 一切似乎都正常部署,它在终端中没有显示错误。 I can see the CloudFormation files in a newly created, dedicated S3 bucket. 我可以在新创建的专用S3存储桶中看到CloudFormation文件。
However, I cannot find the default hello
Lambda function in the AWS Lambda console. 但是,我在AWS Lambda控制台中找不到默认的hello
Lambda函数。
What am I missing? 我错过了什么? Are the CloudFormation files not supposed to create Lambda functions upon deployment? CloudFormation文件是否应该在部署时创建Lambda函数?
The reason the default
hello
Lambda function is not listed in the AWS Lambda console is because your Lambda function was uploaded to the default region (us-east-1), while the Lambda console displays the functions of another region. AWS Lambda控制台中未列出默认hello
Lambda函数的原因是您的Lambda函数已上载到默认区域(us-east-1),而Lambda控制台显示另一个区域的函数。
To set the correct region for your functions, you can use the region field of the serverless.yml
file. 要为函数设置正确的区域,可以使用serverless.yml
文件的region字段。
Make sure the region property is directly under the provider section . 确保region属性直接位于提供者部分下 。 With 2/4 spaces indent. 缩进2/4个空格。 Like this: 像这样:
provider:
region: eu-west-1
Alternatively, you can specify the region at deployment time, like so: 或者,您可以在部署时指定区域,如下所示:
sls deploy --region eu-west-1
Duh, I had made a super silly mistake: 呃,我犯了一个超级愚蠢的错误:
I did not properly set the AWS region
So, I was looking for a lambda function in the wrong region: of course it could not be found! 所以,我在错误的地区寻找一个lambda函数:当然无法找到它!
Before deploying, one must make sure to set the correct region 在部署之前,必须确保设置正确的区域
UPDATE Well actually, I had set the region in serverless.yml
by providing: 更新实际上,我通过提供以下内容在serverless.yml
设置了区域:
region: eu-west-1
However, for some reason the default region was not overwritten, and the function was deployed to the wrong region. 但是,由于某种原因,默认区域未被覆盖,并且该功能已部署到错误的区域。 Odd, that. 奇怪,那。
Anyway, one easy way around this issue is to provide the region at deployment time: 无论如何,围绕这个问题的一个简单方法是在部署时提供该区域:
sls deploy --region eu-west-1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.