amazon-web-services - AWS secret 轮换计划 lambda VpcSecurityGroupIds 的目的

标签 amazon-web-services aws-lambda aws-cloudformation aws-secrets-manager aws-documentdb

我正在使用 CloudFormation 在新 VPC 内设置 DocumentDB 集群。 CloudFormation 正在设置一切,包括 VPC、DocumentDB 密码 key 和 key 轮换。我正在密切关注 AWS::SecretsManager::RotationSchedule 上的 DocumentDB 示例.

我正在设置 AWS::SecretsManager::RotationSchedule HostedRotationLambda对于MongoDBSingleUser。令人困惑的地方是 VpcSecurityGroupIds,它表示:

A comma-separated list of security group IDs applied to the target database.

The templates applies the same security groups as on the Lambda rotation function that is created as part of this stack.

该示例似乎使用 Fn::GetAtt 来获取 VPC 的默认安全组。

          Fn::GetAtt:
          - TestVPC
          - DefaultSecurityGroup

但我专门为数据库设置了一个特殊的安全组,允许 DocumentDB 通过端口 27017 进入。难道我不想简单地为 lambda 引用此 MyCustomDocumentDBSecurityGroup,而不是 VPC 的默认安全组吗?

我想我错过的关键部分是我不理解 VpcSecurityGroupIds目的。看起来它正在将安全组分配给 lambda。但我不确定为什么 lambda 需要安全组。或者更确切地说,lambda 似乎需要数据库安全组的反面 — 它需要端口 27017导出,而不是入口,才能连接到数据库并更新其密码,不是吗?

再次阅读文档后,听起来这个安全组在创建时就被放置在 lambda 上,然后当 lambda 运行时,它将相同的安全组应用于数据库。但为什么?我的模板已将该安全组应用于数据库。也许这是在轮换后将另一个安全组应用于数据库?但为什么呢?

我发现 VpcSecurityGroupIds 是可选的。如果我将其关闭,一切都会好起来并且数据库将保留我已经分配的安全组吗?但为什么该示例要分配安全组呢?

更新:从这里的评论来看,我似乎应该为 lambda 提供一个单独的安全组,以便它访问 VPC 端点。但是Set up automatic rotation for Amazon RDS, Amazon Redshift, or Amazon DocumentDB secrets using the console说“轮换功能……与数据库具有相同的 VPC 和安全组……”这似乎表明我应该将 lambda 设置为使用我为数据库创建的安全组。该文档非常困惑且不一致。

最佳答案

如果我理解正确,您想知道为什么 AWS::SecretsManager::RotationSchedule HostedRotationLambda 要求提供 VpcSecurityGroupIds 列表。正如您从文档中得到的:

A comma-separated list of security group IDs applied to the target database. The templates applies the same security groups as on the Lambda rotation function that is created as part of this stack.

这意味着当使用 VpcSubnetIds 设置此属性时,您的 lambda 将位于 VPC 内。

如果您的 DocumentDB 集群/实例位于私有(private)子网组内,则需要将 lambda 放置在安全组中的同一 VPC 中,并对数据库子网组和特定端口具有显式访问权限。您提到您创建了一个允许访问数据库的特定安全组。这是访问数据库和轮换密码所必需的。

关于amazon-web-services - AWS secret 轮换计划 lambda VpcSecurityGroupIds 的目的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75965992/

相关文章:

amazon-web-services - Elasticsearch 1.3.2升级后的问题

amazon-web-services - 是否可以在 API 网关上添加来自 AWS 自定义身份验证的 HTTP header ?

node.js - 无服务器 AWS Lambda 边缘 : MalformedHandlerName

amazon-web-services - 如何使用 Cloud Formation 为 CloudFront 发行版配置 ACM 证书

amazon-web-services - 标记使用 cloudformation 创建的 Beanstalk 环境

amazon-web-services - 云形成 : How to update a particular without updating the entire stackset?

amazon-web-services - 入站和出站端口需要相同或不同

database - AWS Aurora for PostgreSQL 在 ca-central-1 区域不可用吗?

php - 来自亚马逊s3网站的sql数据库查询

amazon-web-services - Lambda无权执行: dynamodb:GetItem