AWS为一些支持RDS引擎提供了完全配置和现成的旋转支持,包括Amazon (Serverless也是?)
我正在尝试使用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无秘密旋转的简单方法
有可用的例子来为编写我自己的旋转函数吗?
PS:这个问题与从cloudformation创建Aurora集群?有关
发布于 2019-08-07 23:03:18
RotationSchedule资源依赖于SecretTargetAttachment资源。附件资源更新您的秘密字符串值,以包含诸如db引擎、端口和端点等连接信息。
不幸的是,CloudFormation无法知道这两个资源之间的这种隐式依赖。您需要使用附件资源的逻辑id在RotationSchedule资源上放置一个RotationSchedule。
请参阅本例中的RotationSchedule资源- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-rotationschedule.html#aws-resource-secretsmanager-rotationschedule--examples
发布于 2020-07-19 02:17:19
我没有使用无服务器,但我得到了同样的错误。
“数据库引擎必须设置为'mysql‘,才能使用此旋转lambda":KeyError
解决方案
对我来说,问题在于我需要为轮转lambda提供子网和安全组。
CloudFormation模板的草图如下(注意传递给lambda的参数):
DBSecrets:
Type: AWS::SecretsManager::Secret
Properties:
GenerateSecretString:
SecretStringTemplate: '{"username": "XXXXXXXXXX"}'
GenerateStringKey: password
PasswordLength: 24
ExcludeCharacters: '"@/\'
DBSecretsRDSAttachment:
Type: AWS::SecretsManager::SecretTargetAttachment
Properties:
SecretId: !Ref DBSecrets
TargetId: !Ref RDSDatabase
TargetType: AWS::RDS::DBInstance
SecretRotationSchedule:
Type: AWS::SecretsManager::RotationSchedule
DependsOn: DBSecretsRDSAttachment
Properties:
SecretId: !Ref DBSecrets
RotationLambdaARN: !GetAtt MySQLRotationLambda.Outputs.RotationLambdaARN
RotationRules:
AutomaticallyAfterDays: 30
MySQLRotationLambda:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: <ARN_GET_FROM_SERVERLESS_APPLICATION_REPOSITORY>
SemanticVersion: 1.1.0
Parameters:
endpoint: !Sub 'https://secretsmanager.${AWS::Region}.amazonaws.com'
functionName: <Function Name>
vpcSubnetIds: <Comma delimited List of VPC subnet IDs>
vpcSecurityGroupIds: <Comma delimited List of VPC security grouop IDs>
RDSDatabase:
Type: AWS::RDS::DBInstance
Properties:
MasterUsername: !Sub '{{resolve:secretsmanager:${DBSecrets}::username}}'
MasterUserPassword: !Sub '{{resolve:secretsmanager:${DBSecrets}::password}}'
Engine: mysql
DBSubnetGroupName: <Your Subnet Group>
VPCSecurityGroups: <Your Security Group>为什么这是显示错误的原因?
Lambda的旋转经历了以下步骤:
它无法使用挂起的和当前的秘密登录,然后在尝试前一个秘密时出现此错误时失败。挂起的和当前的秘密是有效的,Lambda只是无法连接到数据库。前一个秘密是您最初在上面的CloudFormation模板中提供的秘密。
{
"username": "XXXXXXXXXX",
"password": "XXXXXXXXXX"
}AWS::SecretsManager::SecretTargetAttachment将其更改为正确的格式(对于RDS MySQL单用户):
{
"engine": "mysql",
"host": "<required: instance host name/resolvable DNS name>",
"username": "<required: username>",
"password": "<required: password>",
"dbname": "<optional: database name. If not specified, defaults to None>",
"port": "<optional: TCP port number. If not specified, defaults to 3306>"
}旋转Lambda嵌套堆栈有更多可以传递的参数,只需查看CloudFormation仪表板中的模板即可。
发布于 2020-02-04 22:40:30
在设置PostgreSQL参数"password_encryption: 'scram-sha-256'"时,我遇到了类似的错误。
解决方案是删除使用CloudFormation重新创建的整个MD5堆栈。(更新值未解决错误)
此外,如果Lambdalog没有其他错误的超时,将Lambda函数超时默认为30秒到60秒应该可以解决这个问题。
https://stackoverflow.com/questions/57392215
复制相似问题