aws-api-gateway - 无服务器 : create api key from SecretsManager value

标签 aws-api-gateway serverless-framework aws-secrets-manager

我有一个无服务器堆栈将 API 部署到 AWS。我想使用存储在 Secrets manager 中的 API key 来保护它。这个想法是在 SSM 中拥有 key 的值,在部署时将其拉出并将其用作我的 API key 。
serverless.yml

service: my-app
frameworkVersion: '2'

provider:
  name: aws
  runtime: nodejs12.x
  ...
  apiKeys:
    - name: apikey
      value: ${ssm:myapp-api-key}
据我所知,部署的 API Gateway key 应该与 SSM Secret 相同,但是当我查看控制台时,这两个值是不同的。我在看什么?也没有错误信息。

最佳答案

不久前我遇到了同样的问题,我求助于使用 serverless-add-api-key 插件,因为当 Serverless 为 API Gateway 创建或重用新的 API key 时,我无法理解它。
有了这个插件,您的 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
您还可以使用特定于阶段的配置:
custom:
  apiKeys:
    dev:
      - name: apikey
        value: ${ssm:myapp-api-key}

关于aws-api-gateway - 无服务器 : create api key from SecretsManager value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67296931/

相关文章:

amazon-web-services - 如何防止 terraform 询问在 AWS Secrets Manager 上设置的变量的值?

amazon-web-services - Nest JS 微服务 (lambda) 中的 AWS Secrets 管理器定期失败

amazon-web-services - 为什么我的无服务器 Lambda 无法访问 S3 存储桶和项目?

aws-api-gateway - 通过域名调用API网关

amazon-web-services - AWS NLB 警告 : There is an Internet Gateway attached to these subnets

amazon-web-services - 同一域上的 CloudFront 和 API Gateway 服务

node.js - 带有 Nodejs native 模块的 AWS Lambda

if-statement - 无服务器框架 - 在静态 iam 资源 ARN 和资源部分的引用之间进行选择

asp.net-core - 在 .NET 中配置后如何访问 AWS secret ?

amazon-web-services - 如何使用私有(private)端点类型为我的 Amazon API Gateway API 定义自定义域名