简体   繁体   English

无服务器框架:如何使用CloudFormation进行部署?

[英]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.

相关问题 如何使用无服务器框架正确部署 Lambda 层 - How to properly deploy Lambda layers with Serverless framework 无服务器框架部署不安装节点依赖项 - Serverless framework deploy does not install node dependancies 如何将使用 sharp 库的 macOS 无服务器框架应用程序部署到 AWS? - How can I deploy a Serverless Framework application the macOS that uses the sharp library to AWS? 如何从无服务器cli设置Cloudformation完全访问权限 - How to set Cloudformation full access from the serverless cli aws CI/CD 工作流程的最佳路径是什么? Cloudformation、SAM 还是无服务器框架? - Which is the best path to take for aws CI/CD workflow? Cloudformation, SAM or Serverless framework? 无服务器框架:如何添加外部 NPM 包? - Serverless Framework: How to add external NPM packages? 如何解决无服务器框架 3 中的授权问题? - How to solve authorizer issue in Serverless framework 3? 如何在无服务器框架中包含静态文件? - How to include static files on Serverless Framework? 如何在 Localstack 中使用 graphql、无服务器 lambda 部署 NestJS 服务? - How to deploy NestJS services with graphql, serverless lambda in the Localstack? 如何通过命令行在不同阶段部署无服务器代码? - How to deploy serverless code in different stages via command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM