我正在尝试使用SAM为我的Lambda函数设置一个本地开发环境。直到我在配置中添加了一个对层的引用,我才让一切正常工作。
我按照这里的说明操作:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-layers.html。我在我的template.ymal中添加了我的层版本的ARN,如下所示:
# template.ymal
TestLayerFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: TestLayer
Role: arn:aws:iam::111111111111:role/ReadStreamingTable
CodeUri: src/streaming/test-layer/
Handler: app.handler
Runtime: nodejs8.10
Layers:
- arn:aws:lambda:eu-west-1:111111111111:layer:Global:7但是,当运行"sam本地调用“时,我得到以下错误:
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL:
"https://lambda.eu-west-1a.amazonaws.com/2018-10-31/layers/arn%3Aaws%3Alambda%3Aeu-west-1%3A111111111111%3Alayer%3AGlobal/versions/7"我在配置中添加ARN层的方式似乎就是他们在示例中所做的,所以我不确定是什么导致了这个错误。
发布于 2020-01-26 00:14:10
我知道这不是一个很好的解决方案,但是你能不能不把你的层作为SAM文件的一部分?
如果你看一看this article on the AWS site,他们在同一个yaml文件上同时使用了层和lambda函数,所以你最终会得到这样的结果:
Resources:
TempConversionFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: hello-world/
Handler: app.lambdaHandler
Layers:
- !Ref TempConversionDepLayer
Events:
HelloWorld:
Type: Api
Properties:
Path: /{conversion}/{value}
Method: get
TempConversionDepLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: sam-app-dependencies
Description: Dependencies for sam app [temp-units-conv]
ContentUri: dependencies/
CompatibleRuntimes:
- nodejs6.10
- nodejs8.10
LicenseInfo: 'MIT'
RetentionPolicy: Retainhttps://stackoverflow.com/questions/58118703
复制相似问题