【问题标题】:localstack serverless deploy is not getting deployedlocalstack 无服务器部署未部署
【发布时间】:2021-08-22 18:40:03
【问题描述】:

我正在尝试使用 LocalStackserverless-local 插件在本地部署我的无服务器项目。当我尝试使用 serverless deploy 部署它时,它会引发错误并且无法创建 cloudformation 堆栈。但是,当我将项目部署到真实的 aws 环境时,我设法创建了相同的堆栈。这里可能的问题是什么。我检查了有关类似问题的所有先前问题的答案,似乎没有任何效果。

docker-compose.yml

version: "3.8"

services:
  localstack:
    container_name: "serverless-localstack_main"
    image: localstack/localstack
    ports:
      - "4566-4597:4566-4597"
    environment:
      - AWS_DEFAULT_REGION=eu-west-1
      - EDGE_PORT=4566
      - SERVICES=lambda,cloudformation,s3,sts,iam,apigateway,cloudwatch
    volumes:
      - "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"

serverless.yml

service: serverless-localstack-test

frameworkVersion: '2'

plugins:
  - serverless-localstack

custom:
  localstack:
    debug: true
    host: http://localhost
    edgePort: 4566
    autostart: true
    lambda:
      mountCode: True
    stages:
      - local
    endpointFile: config.json


provider:
  name: aws
  runtime: nodejs12.x
  lambdaHashingVersion: 20201221
  stage: local
  region: eu-west-1
  deploymentBucket:
    name: deployment

functions:
  hello:
    handler: handler.hello

Config.json(具有端点)

{
    "CloudFormation": "http://localhost:4566",
    "CloudWatch": "http://localhost:4566",
    "Lambda": "http://localhost:4566",
    "S3": "http://localhost:4566"
}

Localstack 容器中的错误

serverless-localstack_main | 2021-06-04T17:41:49:WARNING:localstack.utils.cloudformation.template_deployer: Error calling
 <bound method ClientCreator._create_api_method.<locals>._api_call of 
<botocore.client.Lambda object at 0x7f31f359a4c0>> with params: {'FunctionName': 
'serverless-localstack-test-local-hello', 'Runtime': 'nodejs12.x', 'Role': 
'arn:aws:iam::000000000000:role/serverless-localstack-test-local-eu-west-1-lambdaRole',
 'Handler': 'handler.hello', 'Code': {'S3Bucket': '__local__', 'S3Key': 
'/Users/charles/Documents/Practice/serverless-localstack-test'}, 'Timeout': 6,
 'MemorySize': 1024} for resource: {'Type': 'AWS::Lambda::Function', 'Properties': 
{'Code': {'S3Bucket': '__local__', 'S3Key': 
'/Users/charles/Documents/Practice/serverless-localstack-test'}, 'Handler': 
'handler.hello', 'Runtime': 'nodejs12.x', 'FunctionName': 'serverless-localstack-test-
local-hello', 'MemorySize': 1024, 'Timeout': 6, 'Role': 
'arn:aws:iam::000000000000:role/serverless-localstack-test-local-eu-west-1-lambdaRole'}, 
'DependsOn': ['HelloLogGroup'], 'LogicalResourceId': 'HelloLambdaFunction', 
'PhysicalResourceId': None, '_state_': {}}

【问题讨论】:

    标签: amazon-web-services serverless-framework serverless localstack


    【解决方案1】:

    我使用这个插件解决了这个问题:https://www.serverless.com/plugins/serverless-deployment-bucket

    【讨论】:

      【解决方案2】:

      您需要对文件进行一些调整。

      • 更新您的 docker-compose.yml,使用参考 docker compose localstack,你可以查看here

      • 使用正常工作的模板,AWS 文档页面有几个 例子,你可以查看here

      • 用下一个命令aws cloudformation create-stack --endpoint-url http://localhost:4566 --stack-name samplestack --template-body file://lambda.yml --profile dev运行它

      您还可以使用 Python 和 next 命令运行 localstack

      pip install localstack 
      localstack start
      

      【讨论】:

        猜你喜欢
        • 2023-01-20
        • 1970-01-01
        • 2021-01-07
        • 2019-08-26
        • 2023-01-27
        • 2022-11-07
        • 2019-12-24
        • 2019-04-30
        • 1970-01-01
        相关资源
        最近更新 更多