xSh*_*ase 5 aws-api-gateway serverless-framework aws-secrets-manager
我有一个无服务器堆栈,将 API 部署到 AWS。我想使用存储在 Secrets Manager 中的 API 密钥来保护它。这个想法是在 SSM 中获取密钥的值,在部署时拉取它并将其用作我的 API 密钥。
无服务器.yml
service: my-app
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x
...
apiKeys:
- name: apikey
value: ${ssm:myapp-api-key}
Run Code Online (Sandbox Code Playgroud)
据我所知,部署的 API Gateway 密钥应该与 SSM Secret 相同,但是当我在控制台中查看时,这两个值是不同的。我在忽略什么?也没有错误消息。
不久前我遇到了同样的问题,我求助于使用该serverless-add-api-key
插件,因为当 Serverless 为 API Gateway 创建或重用新的 API 密钥时,它对我来说无法理解。
使用这个插件你serverless.yml
会看起来像这样:
service: my-app
frameworkVersion: '2'
plugins:
- serverless-add-api-key
custom:
apiKeys:
- name: apikey
value: ${ssm:myapp-api-key}
functions:
your-function:
runtime: ...
handler: ...
name: ...
events:
- http:
...
private: true
Run Code Online (Sandbox Code Playgroud)
您还可以使用特定于阶段的配置:
custom:
apiKeys:
dev:
- name: apikey
value: ${ssm:myapp-api-key}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1513 次 |
最近记录: |