我们有一个简单的无服务器应用程序,其中包含dynamo DB表,一些lambda和API端点。目前,我们已在开发阶段部署了该应用。
我们在部署到产品阶段时遇到了一些麻烦。
这是serverless.yaml文件。
service: lookups
# app and org for use with dashboard.# serverless.com
app: lookups
org: xxxxxx
provider:
name: aws
runtime: python3.8
environment:
DYNAMO_DB_LOOKUP_TABLE_NAME: lookup_${self:provider.stage}
S3_BUCKET: com.yyyyy.lookups.${self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:GetItem
Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/${self:provider.environment.DYNAMO_DB_LOOKUP_TABLE_NAME}"
functions:
createOrUpdateLookups:
handler: createOrUpdateLookups.createOrUpdateLookups
description: create or update lookup entry in dynamodb
environment:
lookupTable: ${self:provider.environment.DYNAMO_DB_LOOKUP_TABLE_NAME}
events:
- s3:
bucket: ${self:provider.environment.S3_BUCKET}
event: s3:ObjectCreated:*
rules:
- suffix: .json
getLookup:
handler: getLookup.getLookup
description: get persigned url for a lookup by location and lookup type
environment:
lookupTable: ${self:provider.environment.DYNAMO_DB_LOOKUP_TABLE_NAME}
lookupBucket: ${self:provider.environment.S3_BUCKET}
events:
- http:
path: v1/lookup
method: get
request:
parameters:
querystrings:
location: true
lookupType: true
resources:
Resources:
lookupTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: ${self:provider.environment.DYNAMO_DB_LOOKUP_TABLE_NAME}
AttributeDefinitions:
- AttributeName: location
AttributeType: S
- AttributeName: lookup
AttributeType: S
KeySchema:
- AttributeName: location
KeyType: "HASH"
- AttributeName: lookup
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
我们使用以下cli命令将其部署到开发阶段:
serverless deploy
这在lookups-dev
CloudFormtion中创建了一个堆栈,该堆栈称为DymanoDB表DB表,其名称为lookup-dev
lambdas,其名称为lookups-dev-createOrUpdateLookups
and lookups-dev-getLookup
。
现在,当尝试使用此cli命令部署到称为prod的新阶段时
serverless deploy --stage prod
我们收到一个错误消息,说明表lookups-dev已存在于具有lookups-dev堆栈的堆栈ID的堆栈中。
这是完整的错误:
发生错误:lookupTable-堆栈arn:aws:cloudformation:us-east-1:aaaaabbbbbbbccccccdddddd:stack / lookups-dev / wwwwwww-wwwwwww-wwwwwwaws中已经存在lookup_dev。
问题:当我们已经在开发阶段部署了应用程序时,如何将其部署到新阶段。
发生的事情是,您需要确保表的名称在不同的阶段进行更改。我看到您习惯${self:provider.stage}
尝试执行此操作,但所有操作都是使用provider部分下的stage值,并且因为您尚未设置,所以它使用了dev
always的默认值。我建议在提供程序下添加以下行,以便您具有以下内容:
provider:
stage: ${opt:stage, 'dev'}
这意味着,如果您使用--stage在CLI上传递阶段,则会将provider.stage设置为该值或默认为dev。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句