Tom*_*Tom 9 aws-cloudformation terraform serverless-framework serverless
我遵循了一个出色的指南(无服务器堆栈),它创建了一个带有反应前端的典型CRUD无服务器基础架构.它正在使用AWS 的无服务器框架.
我不喜欢的是,为了引导设置,有很多手动点击GUI(主要是亚马逊的控制台界面).即,设置不受版本控制,并且不易重现.使用CI/CD进程等扩展它并不容易.在此示例中,需要手动设置以下资源:
从代码构建的唯一资源是无服务器函数(lambdas)本身,以及API网关实例.这就是无服务器框架使用其serverless.yml文件所做的事情.但是不会自动创建上述所有资源.有时需要引用它们来使用它们的ARN,但它们不是由serverless.yml配置创建的.在生产中运行这样的系统(严重依赖于通过GUI手动创建服务)似乎存在风险.
我当时认为解决这个问题的方法是使用Terraform或Cloudformation.但无服务器框架本身已经使用Cloudformation来设置Lambdas,但不是用于其他资源.那么如何消除这种差距呢?换句话说,如何在代码中重建无服务器堆栈中描述的整个设置?
CloudFormation设置无服务器似乎很奇怪,也许是不可能的,然后它有自己的Cloudformation模板来设置lambdas.扩展无服务器框架可能更有意义,不仅要定义需要在其上创建的功能和API网关,serverless deploy
还要定义其他资源,如DynamoDB或Cognito用户池.是否有人做过这样的例子或尝试?
我同意这方面的文档会在这里提出一个很好的拉取请求.
你在serverless
底层使用CloudFormation 是正确的.该框架确实通过您的resources
密钥向您公开底层的CloudFormation机制serverless.yml
.
我认为该框架的目的是使用常规的旧CloudFormation语法将剩余的这些资源(Cognito stuff,S3等)放在文件的resources:
部分中.serverless.yml
例如,除了无服务器功能之外,此文件还将创建DynamoDB表和S3存储桶:
service: aws-nodejs # NOTE: update this with your service name
provider:
name: aws
runtime: nodejs6.10
functions:
hello:
handler: handler.deletecustomer
events:
- http:
path: /deletecustomer
method: post
cors: true
resources:
Resources:
tablenotes:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: noteId
AttributeType: S
- AttributeName: userId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: noteId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: '5'
WriteCapacityUnits: '5'
mysamplebucket:
Type: AWS::S3::Bucket
Properties:
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: error.html
AccessControl: Private
VersioningConfiguration:
Status: Suspended
Run Code Online (Sandbox Code Playgroud)
如果您是CloudFormation的新手,我还建议您浏览一下CloudFormer.
归档时间: |
|
查看次数: |
791 次 |
最近记录: |