gpt4 book ai didi

amazon-web-services - 无服务器示例不适用于无服务器本地堆栈插件

转载 作者:行者123 更新时间:2023-12-03 23:50:08 29 4
gpt4 key购买 nike

我正在运行 serverless GitHub 官方页面上的一个示例,当我直接在我的 AWS 账户上部署时,它开箱即用。

现在,当我尝试通过相应地更改 serverless.yml 来激活 serverless-localstack 插件时:

service: serverless-rest-api-with-dynamodb

frameworkVersion: ">=1.1.0 <2.0.0"

provider:
name: aws
runtime: python2.7
environment:
DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"

custom:
localstack:
stages:
- local
- dev
endpoints:
S3: http://localhost:4572
DynamoDB: http://localhost:4570
CloudFormation: http://localhost:4581
Elasticsearch: http://localhost:4571
ES: http://localhost:4578
SNS: http://localhost:4575
SQS: http://localhost:4576
Lambda: http://localhost:4574
Kinesis: http://localhost:4568

plugins:
- serverless-localstack

functions:
create:
handler: todos/create.create
events:
- http:
path: todos
method: post
cors: true

list:
handler: todos/list.list
events:
- http:
path: todos
method: get
cors: true

get:
handler: todos/get.get
events:
- http:
path: todos/{id}
method: get
cors: true

update:
handler: todos/update.update
events:
- http:
path: todos/{id}
method: put
cors: true

delete:
handler: todos/delete.delete
events:
- http:
path: todos/{id}
method: delete
cors: true

resources:
Resources:
TodosDynamoDbTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
-
AttributeName: id
AttributeType: S
KeySchema:
-
AttributeName: id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:provider.environment.DYNAMODB_TABLE}

我在 localstack 端收到以下错误(在 docker 中运行):
localstack_1  | 2019-12-04 09:48:15,260:API: 127.0.0.1 - - [04/Dec/2019 09:48:15] "GET /serverless-rest-api-with-dynamodb-local-ServerlessDeploymentBucket-5YYKLD61WXMT?location HTTP/1.1" 404 -
localstack_1 | 2019-12-04T09:48:15:DEBUG:localstack.services.cloudformation.cloudformation_listener: Error response from CloudFormation (400) POST /: b'<ErrorResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/">\n <Error>\n <Type>Sender</Type>\n <Code>ValidationError</Code>\n <Message>Stack with id serverless-rest-api-with-dynamodb-local does not exist</Message>\n </Error>\n <RequestId>cf4c737e-5ae2-11e4-a7c9-ad44eEXAMPLE</RequestId>\n</ErrorResponse>'
localstack_1 | 2019-12-04T09:48:15:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently updating stack resource serverless-rest-api-with-dynamodb-local/ServerlessDeploymentBucket: None
localstack_1 | 2019-12-04T09:48:15:ERROR:localstack.services.cloudformation.cloudformation_starter: Unable to parse and create resource "ServerlessDeploymentBucket": 400 Bad Request: <?xml version="1.0" encoding="UTF-8"?>
localstack_1 | <Error>
localstack_1 | <Code>InvalidBucketName</Code>
localstack_1 | <Message>The specified bucket is not valid.</Message>
localstack_1 |
localstack_1 | <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID>
localstack_1 | </Error> Traceback (most recent call last):
localstack_1 | File "/opt/code/localstack/localstack/services/cloudformation/cloudformation_starter.py", line 173, in parse_and_create_resource
localstack_1 | return _parse_and_create_resource(logical_id, resource_json, resources_map, region_name)
localstack_1 | File "/opt/code/localstack/localstack/services/cloudformation/cloudformation_starter.py", line 229, in _parse_and_create_resource
localstack_1 | resource_json_arns_fixed, resources_map, region_name)
localstack_1 | File "/opt/code/localstack/.venv/lib/python3.7/site-packages/moto/cloudformation/parsing.py", line 306, in parse_and_create_resource
localstack_1 | resource_name, resource_json, region_name)
localstack_1 | File "/opt/code/localstack/.venv/lib/python3.7/site-packages/moto/s3/models.py", line 701, in create_from_cloudformation_json
localstack_1 | bucket = s3_backend.create_bucket(resource_name, region_name)
localstack_1 | File "/opt/code/localstack/.venv/lib/python3.7/site-packages/moto/s3/models.py", line 714, in create_bucket
localstack_1 | raise InvalidBucketName()
localstack_1 | moto.s3.exceptions.InvalidBucketName: 400 Bad Request: <?xml version="1.0" encoding="UTF-8"?>
localstack_1 | <Error>
localstack_1 | <Code>InvalidBucketName</Code>
localstack_1 | <Message>The specified bucket is not valid.</Message>
localstack_1 |
localstack_1 | <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID>
localstack_1 | </Error>
localstack_1 |
localstack_1 | 2019-12-04T09:48:15:DEBUG:localstack.services.cloudformation.cloudformation_listener: Error response from CloudFormation (400) POST /: b'<?xml version="1.0" encoding="UTF-8"?>\n<Error>\n <Code>InvalidBucketName</Code>\n <Message>The specified bucket is not valid.</Message>\n \n <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID>\n</Error>'
localstack_1 | 2019-12-04 09:48:34,571:API: 127.0.0.1 - - [04/Dec/2019 09:48:34] "GET /serverless-rest-api-with-dynamodb-local-ServerlessDeploymentBucket-C5ZNB3XCGTSA?location HTTP/1.1" 404 -
localstack_1 | 2019-12-04T09:48:34:DEBUG:localstack.services.cloudformation.cloudformation_listener: Error response from CloudFormation (400) POST /: b'<ErrorResponse xmlns="http://cloudformation.amazonaws.com/doc/2010-05-15/">\n <Error>\n <Type>Sender</Type>\n <Code>ValidationError</Code>\n <Message>Stack with id serverless-rest-api-with-dynamodb-local does not exist</Message>\n </Error>\n <RequestId>cf4c737e-5ae2-11e4-a7c9-ad44eEXAMPLE</RequestId>\n</ErrorResponse>'
localstack_1 | 2019-12-04T09:48:34:DEBUG:localstack.services.cloudformation.cloudformation_starter: Currently updating stack resource serverless-rest-api-with-dynamodb-local/ServerlessDeploymentBucket: None
localstack_1 | 2019-12-04T09:48:34:ERROR:localstack.services.cloudformation.cloudformation_starter: Unable to parse and create resource "ServerlessDeploymentBucket": 400 Bad Request: <?xml version="1.0" encoding="UTF-8"?>
localstack_1 | <Error>
localstack_1 | <Code>InvalidBucketName</Code>
localstack_1 | <Message>The specified bucket is not valid.</Message>
localstack_1 |
localstack_1 | <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID>
localstack_1 | </Error> Traceback (most recent call last):
localstack_1 | File "/opt/code/localstack/localstack/services/cloudformation/cloudformation_starter.py", line 173, in parse_and_create_resource
localstack_1 | return _parse_and_create_resource(logical_id, resource_json, resources_map, region_name)
localstack_1 | File "/opt/code/localstack/localstack/services/cloudformation/cloudformation_starter.py", line 229, in _parse_and_create_resource
localstack_1 | resource_json_arns_fixed, resources_map, region_name)
localstack_1 | File "/opt/code/localstack/.venv/lib/python3.7/site-packages/moto/cloudformation/parsing.py", line 306, in parse_and_create_resource
localstack_1 | resource_name, resource_json, region_name)
localstack_1 | File "/opt/code/localstack/.venv/lib/python3.7/site-packages/moto/s3/models.py", line 701, in create_from_cloudformation_json
localstack_1 | bucket = s3_backend.create_bucket(resource_name, region_name)
localstack_1 | File "/opt/code/localstack/.venv/lib/python3.7/site-packages/moto/s3/models.py", line 714, in create_bucket
localstack_1 | raise InvalidBucketName()
localstack_1 | moto.s3.exceptions.InvalidBucketName: 400 Bad Request: <?xml version="1.0" encoding="UTF-8"?>
localstack_1 | <Error>
localstack_1 | <Code>InvalidBucketName</Code>
localstack_1 | <Message>The specified bucket is not valid.</Message>
localstack_1 |
localstack_1 | <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID>
localstack_1 | </Error>
localstack_1 |
localstack_1 | 2019-12-04T09:48:34:DEBUG:localstack.services.cloudformation.cloudformation_listener: Error response from CloudFormation (400) POST /: b'<?xml version="1.0" encoding="UTF-8"?>\n<Error>\n <Code>InvalidBucketName</Code>\n <Message>The specified bucket is not valid.</Message>\n \n <RequestID>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestID>\n</Error>'
serverless.yml 中是否缺少使 localstack 插件正常工作的配置?

我用于部署的命令是:

SLS_DEBUG=3 serverless deploy --stage local --region us-east-1

最佳答案

我只尝试了 localstack 一次并且没有成功使用本地堆栈。我已经为你搜索并找到了答案。看看它是否工作。

provider:
deploymentBucket:
name: ${self:service}-${opt:stage}-deployment-bucket

引用: https://github.com/localstack/serverless-localstack/issues/30

关于amazon-web-services - 无服务器示例不适用于无服务器本地堆栈插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59173479/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com