我在使用无服务器框架时遇到了一些问题,因为我不小心在另一个服务上使用了相同的服务名称。
An error occurred: tableX - TableX already exists.
假设我有两个“ serverless.yml ”文件,两者都具有相同的服务名称。其中一个(我们称之为“ test1 ”)有资源(DynamoDB 表),另一个没有(“ test2 ”)。就像下面的片段:
测试1
service: sandbox-core
provider:
name: aws
stage: core
runtime: nodejs6.10
region: sa-east-1
memorySize: 128
timeout: 300
resources:
Resources:
table3:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
TableName: SandboxTable3
AttributeDefinitions:
-
AttributeName: provider
AttributeType: S
-
AttributeName: appId
AttributeType: S
KeySchema:
-
AttributeName: provider
KeyType: HASH
-
AttributeName: appId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
table4:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
TableName: SandboxTable4
AttributeDefinitions:
-
AttributeName: session
AttributeType: S
KeySchema:
-
AttributeName: session
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 1
functions:
auth:
handler: handler.auth
events:
- http:
path: auth/{session}/{provider}/{appId}
method: get
cors: true
测试2
service: sandbox-core
provider:
name: aws
stage: core
runtime: nodejs6.10
region: sa-east-1
memorySize: 128
timeout: 300
functions:
createCustomData:
handler: handler.createCustomData
events:
- http:
path: teste2
method: post
cors: true
当我sls deploy
是“ test1 ”时,他会根据我的需要创建表,使用DeletionPolicy: Retain
, 为具有非常敏感数据的表。然后我sls deploy
“ test2 ”有其他功能但没有任何资源(DynamoDB 表),他做了预期的事情:跳过表的删除。
但是,当我再次部署“ test1 ”时,他无法识别这些表,他开始“创建”现有表而不是更新它们,并且无法部署。
我需要没有被删除的表,并且需要服务上的功能。看起来 Cloud Formation 在第一次部署时丢失了创建表的跟踪。
我不想像在这个github 线程上所说的那样分离服务(一个仅用于资源) 。我需要正在运行的表,它有很多数据,备份和恢复到另一个表的成本太高,很多用户可能会受到影响。
那么,我如何告诉 Cloud Formation Stack 我正在更新该表,而不是尝试创建它?如何跟踪 Cloud Formation Stack 上的服务?而且,我如何防止在没有资源的情况下部署具有资源的服务?
这种情况的最佳解决方案是什么?希望我的问题足够清楚,可以理解。