4

我正在从官方无服务器 GitHub页面运行一个示例,当我直接在我的 AWS 帐户上部署时,它开箱即用。

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

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.ymllocalstack 插件是否缺少配置?

我用于部署的命令是:

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

4

2 回答 2

2

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

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

参考:https ://github.com/localstack/serverless-localstack/issues/30

于 2019-12-04T10:28:01.813 回答
1

我曾经遇到过这个问题,按照@arun-k 的建议,我添加了deploymentBucket. 尽管我遇到了其他问题,但它运行良好,因此我提取了LocalStack(ie image: localstack/localstack:0.10.5) 的标记图像而不是稳定版本,并且我没有deploymentBucket再次指定它也有效。

认为它可能对其他人有用。

于 2020-06-18T02:46:04.350 回答