【发布时间】:2019-08-27 18:32:40
【问题描述】:
使用Serverless Framework
部署 AWS Lambda 函数,Serverless 创建(或接收)
特定的 URL 端点字符串。我想使用该字符串(作为变量)
在serverless.yml 规范文件的另一部分中。
该 URL 端点是否可用作 serverless.yml 中的变量?
Serverless Framework documentation on AWS-related variables
似乎没有回答这种情况。
详细信息:我的 serverless.yml 包含一个 provider: 规范
类似于:
provider:
name: aws
runtime: python3.6
memorySize: 512
region: ${opt:region, 'eu-west-1'}
profile: ${opt:profile, 'default'}
stage: ${opt:stage, 'staging'}
还有一个functions: 部分,以:
functions:
round-control:
name: ${self:provider.stage}-round-control
runtime: nodejs8.10
handler: round/control/app.lambdaHandler
events:
- http:
path: round/control
method: get
之后
serverless deploy --profile [my-aws-profile]
Lambda 函数sample-experiments-staging-round-control
报告在端点可用
https://1a234bc5de.execute-api.eu-west-1.amazonaws.com/staging/round/control.
问题:Serverless 中是否有一个变量包含
1a234bc5de,或1a234bc5de.execute-api,甚至可能
1a234bc5de.execute-api.eu-west-1.amazonaws.com?
(显然,如果我知道第一个,我也可以构造最后两个。)
使用该变量,我可以构建完整的 URL 端点,我
需要在serverless.yml 文件中的另一个位置。
注意1a234bc5de 不是动态生成的随机数
字符串 - 我当前的项目是(每个阶段,每个区域)“固定”到
相同的字符串。也许该字符串是在 AWS Lambda 或
AWS API 网关?
【问题讨论】:
-
太好了,@jarmod。它似乎在 CloudFormation 变量中可用。它记录在 docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/… 和
AWS::ApiGateway::RestApi资源上的Ref包含该 ID。
标签: amazon-web-services aws-lambda aws-api-gateway serverless-framework