Skip to content
forked from aws/aws-cdk

Commit

Permalink
fix(secretsmanager): rotation function name exceeds 64 chars
Browse files Browse the repository at this point in the history
Get the last 64 chars of the `uniqueId`.

See aws#7885 (comment).

Closes aws#7885
  • Loading branch information
jogold authored and Andrew Hammond committed Jun 8, 2020
1 parent 02ddab8 commit 5db4871
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-secretsmanager/lib/secret-rotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ export class SecretRotation extends Construct {
throw new Error('The `masterSecret` must be specified for application using the multi user scheme.');
}

const rotationFunctionName = this.node.uniqueId;
// Max length of 64 chars, get the last 64 chars
const uniqueId = this.node.uniqueId;
const rotationFunctionName = uniqueId.substring(Math.max(uniqueId.length - 64, 0), uniqueId.length);

const securityGroup = props.securityGroup || new ec2.SecurityGroup(this, 'SecurityGroup', {
vpc: props.vpc,
Expand Down
64 changes: 64 additions & 0 deletions packages/@aws-cdk/aws-secretsmanager/test/test.secret-rotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,68 @@ export = {

test.done();
},

'rotation function name does not exceed 64 chars'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const secret = new secretsmanager.Secret(stack, 'Secret');
const target = new ec2.Connections({
defaultPort: ec2.Port.tcp(3306),
securityGroups: [new ec2.SecurityGroup(stack, 'SecurityGroup', { vpc })],
});

// WHEN
const id = 'SecretRotation'.repeat(5);
new secretsmanager.SecretRotation(stack, id, {
application: secretsmanager.SecretRotationApplication.MYSQL_ROTATION_SINGLE_USER,
secret,
target,
vpc,
});

// THEN
expect(stack).to(haveResource('AWS::Serverless::Application', {
Parameters: {
endpoint: {
'Fn::Join': [
'',
[
'https://secretsmanager.',
{
Ref: 'AWS::Region',
},
'.',
{
Ref: 'AWS::URLSuffix',
},
],
],
},
functionName: 'RotationSecretRotationSecretRotationSecretRotationSecretRotation',
vpcSecurityGroupIds: {
'Fn::GetAtt': [
'SecretRotationSecretRotationSecretRotationSecretRotationSecretRotationSecurityGroupBFCB171A',
'GroupId',
],
},
vpcSubnetIds: {
'Fn::Join': [
'',
[
{
Ref: 'VPCPrivateSubnet1Subnet8BCA10E0',
},
',',
{
Ref: 'VPCPrivateSubnet2SubnetCFCDAA7A',
},
],
],
},
},
}));

test.done();
},
};

0 comments on commit 5db4871

Please sign in to comment.