gpt4 book ai didi

aws-api-gateway - 使用无服务器将 lambda 函数部署到 LocalStack 时无法使用 httpApi

转载 作者:行者123 更新时间:2023-12-05 05:01:11 25 4
gpt4 key购买 nike

总体而言,我对无服务器还很陌生,并尝试在我的机器上设置 LocalStack。我已成功将测试 lambda 函数部署到 LocalStack,但目前面临有关 API 网关的问题。

在使用以下配置进行部署时,一切正常,我能够使用 http 正确访问 lambda 函数,并且在部署结束时像往常一样打印生成的端点:

service: localtest

frameworkVersion: ">=1.74.1"

provider:
name: aws
runtime: nodejs12.x
stage: local

plugins:
- serverless-localstack

custom:
localstack:
stages:
- local
host: http://localhost
autostart: true
endpoints:
S3: http://localhost:4566
DynamoDB: http://localhost:4566
CloudFormation: http://localhost:4566
Elasticsearch: http://localhost:4566
ES: http://localhost:4566
SNS: http://localhost:4566
SQS: http://localhost:4566
Lambda: http://localhost:4566
Kinesis: http://localhost:4566
lambda:
mountCode: True
docker:
sudo: False

functions:
hello:
handler: handler.hello
events:
- http:
method: get
path: /

serverless deploy 的结果输出:

Service Information
service: localtest
stage: local
region: us-east-1
stack: localtest-local
resources: 10
api keys:
None
endpoints:
http://localhost:4567/restapis/720w6afoyh/local/_user_request_
functions:
hello: localtest-local-hello
layers:
None

但是,当尝试在事件中使用 httpApi 实现时

 - httpApi:
method: get
path: /

我从 localstack 收到几个错误,该函数似乎已部署但不输出路径。

来自 LocalStack 的错误日志:

2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Integration
2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Stage
2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Api
2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Route
2020-07-09T11:39:50:WARNING:moto: No Moto CloudFormation support for AWS::ApiGatewayV2::Api
2020-07-09T11:39:55:WARNING:localstack.services.cloudformation.cloudformation_starter: Unable to resolve "Ref" attribute for: {'Ref': 'HelloLambdaVersionFjNrIW0CS0DGT44Agi2AjgeDtzxVf8vf0JBR6XRariM'} - HelloLambdaVersionFjNrIW0CS0DGT44Agi2AjgeDtzxVf8vf0JBR6XRariM - <class 'moto.awslambda.models.LambdaVersion'>

最佳答案

我遇到了同样的问题。这显然只在 localstack 的 pro 版本中受支持,在免费版本中不受支持。

AWS docs请注意,根据 localstack repo,HTTP API 使用 API 网关的 -v2 版本,并且仅支持此版本, 在专业版中。

关于aws-api-gateway - 使用无服务器将 lambda 函数部署到 LocalStack 时无法使用 httpApi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62814212/

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