首页 > 解决方案 > 使用 CloudFormation(和 Lambda 轮换模板)的 Aurora Serverless 密码轮换设置

问题描述

AWS 为一些受支持的 RDS 引擎提供了完全配置且随时可用的轮换支持,包括 Amazon Aurora(也无服务器?)

我正在尝试使用以下方法在我的 CloudFormation 模板中设置密码轮换AWS::SecretsManager::RotationSchedule(请注意,这不是一个功能齐全的模板,只是一个说明):

  DBCluster:
    Type: AWS::RDS::DBCluster
    Properties:
      Engine        : aurora
      EngineMode    : serverless
      EngineVersion : 5.6.10a

  Secret:
    Type: AWS::SecretsManager::Secret
    Properties:
      GenerateSecretString:
        SecretStringTemplate: '{"username": "admin"}'
        GenerateStringKey: password
        PasswordLength: 20
        ExcludeCharacters: '"@/\'

  SecretTargetAttachment:
    Type: AWS::SecretsManager::SecretTargetAttachment
    Properties:
      SecretId: !Ref Secret
      TargetId: !Ref DBCluster
      TargetType: AWS::RDS::DBCluster

  SecretRotation:
    Type: AWS::SecretsManager::RotationSchedule
    Properties:
      SecretId: !Ref UserAdminSecret
      RotationLambdaARN: <ARN_GET_FROM_SERVERLESS_APPLICATION_REPOSITORY>
      RotationRules:
        AutomaticallyAfterDays: 1

但 AWS Lambda 轮换函数失败并显示以下消息:

“数据库引擎必须设置为 'mysql' 才能使用此旋转 lambda”:KeyError

AWS 提供的 AWS Lambda 轮换功能似乎不支持 Aurora Serverless。

是否有使用现有 Lambda 轮换模板设置 Aurora Serverless 密钥轮换的简单方法?

任何可用于为 Aurora Serverless 编写我自己的轮换函数的示例?

PS:这个问题与从 cloudformation 创建 Aurora Serverless Cluster 有点相关?

标签: amazon-web-servicesamazon-cloudformationamazon-rdsaws-secrets-manageraws-aurora-serverless

解决方案


RotationSchedule 资源依赖于 SecretTargetAttachment 资源。附件资源更新您的秘密字符串值以包含连接信息,例如数据库引擎、端口和端点。

不幸的是,CloudFormation 无法了解两种资源之间的这种隐式依赖关系。您需要使用附件资源的逻辑 ID 在 RotationSchedule 资源上放置一个DependsOn 。

请参阅此示例中的 RotationSchedule 资源 - https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-rotationschedule.html#aws-resource-secretsmanager-rotationschedule--examples


推荐阅读