localstack 无服务器部署未部署

时间:2021-06-04 17:45:54

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

我正在尝试使用 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_': {}}

1 个答案:

答案 0 :(得分:0)

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