如何在 Serverless 的环境变量中获取 API 网关 url
How to get API gateway url in Environment variable in Serverless
我正在开发一个无服务器框架(云形成),我在同一个 AWS 区域创建了两个堆栈,每个堆栈 serverless.yml(stack1, stack2) 都有自己的 API。如何在 stack-2 yml.
中获取 stack-1(yml) API URL
Stack-1(serverless1.yml)
functions:
tGateWay:
handler: src/handlers/tGateWay.handler
name: ${self:provider.stage}-tGateWay
environment:
first: ${self:provider.stage}-firstlambda
events:
- http:
method: any
path: /tGateway
private: true
Stack-2(serverless2.yml)
functions:
tModule:
handler: src/handlers/tModule.handler
name: ${self:provider.stage}-tModule
environment:
find: ${self:provider.stage}-find
T_GATEWAY: https://xxxxxxxxx.execute-api.xxxxxxx-1.amazonaws.com/dev/tGateway
在那里 T_GATEWAY 我想访问 stack-1 API 网关 URL
提前致谢!
您可以使用 SecretsManager,您可以使用类似这样的方式将它从那里导入到您的函数中:
iamRoleStatements:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
functions:
handler.js
myHandler:
handler: myHandler
environment:
yourSecretKey: "{{resolve:secretsmanager:secretYouCreated:SecretString:yourSecretKey}}"
我正在开发一个无服务器框架(云形成),我在同一个 AWS 区域创建了两个堆栈,每个堆栈 serverless.yml(stack1, stack2) 都有自己的 API。如何在 stack-2 yml.
中获取 stack-1(yml) API URLStack-1(serverless1.yml)
functions:
tGateWay:
handler: src/handlers/tGateWay.handler
name: ${self:provider.stage}-tGateWay
environment:
first: ${self:provider.stage}-firstlambda
events:
- http:
method: any
path: /tGateway
private: true
Stack-2(serverless2.yml)
functions:
tModule:
handler: src/handlers/tModule.handler
name: ${self:provider.stage}-tModule
environment:
find: ${self:provider.stage}-find
T_GATEWAY: https://xxxxxxxxx.execute-api.xxxxxxx-1.amazonaws.com/dev/tGateway
在那里 T_GATEWAY 我想访问 stack-1 API 网关 URL
提前致谢!
您可以使用 SecretsManager,您可以使用类似这样的方式将它从那里导入到您的函数中:
iamRoleStatements:
- Effect: Allow
Action:
- secretsmanager:GetSecretValue
functions:
handler.js
myHandler:
handler: myHandler
environment:
yourSecretKey: "{{resolve:secretsmanager:secretYouCreated:SecretString:yourSecretKey}}"