我有以下模板,我在cloudformation UI中使用它来创建dynamoDB表.我想创建一个表,其中PrimaryKey为ID,sortKey为Value
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "DB Description",
"Resources" : {
"TableName" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions": [ {
"AttributeName" : "ID",
"AttributeType" : "S"
}, {
"AttributeName" : "Value",
"AttributeType" : "S"
} ],
"KeySchema": [
{
"AttributeName": "ID",
"KeyType": "HASH"
}
]
},
"TableName": "TableName"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在CF UI上,我单击新堆栈,template从本地计算机指向该文件,为堆栈命名并单击下一步.一段时间后,我收到错误,指出Property AttributeDefinitions与表的KeySchema和二级索引不一致
我在serverless.yml文件中定义了以下资源.它非常适合为我所有不同的开发阶段创建资源.
resources:
Resources:
uploadBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:service}-${self:custom.stage}-uploads
visitsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.visitsTable}
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: visitId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: visitId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}}
WriteCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.stage}}
Run Code Online (Sandbox Code Playgroud)
问题是......如果我sls remove在删除数据库时这样做,它还会删除其他所有内容,包括lambda函数及其api网关端点,我需要保留它们,因为我已经为它们明确设置了策略. 如何告诉无服务器我只想删除数据库或S3或其他任何东西而不是其余的?
我试过的事情:
我在AWS上手动删除了,但是如果你这样做并且执行sls部署它不会再次创建数据库!所以不确定最好的方法来做到这一点......
整个Serverless.yml文件
service: mydomain-api
# Use serverless-webpack plugin to transpile ES6/ES7
plugins:
- serverless-webpack
- serverless-domain-manager
custom:
webpackIncludeModules: true
stage: ${opt:stage, self:provider.stage}
visitsTable: "${self:service}-visits-${self:custom.stage}"
domains:
prod: api.mydomain.com
staging: staging-api.mydomain.com
dev: dev-api.mydomain.com …Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-lambda aws-api-gateway serverless-framework serverless