Skip to content

Commit

Permalink
add a check
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush987goyal committed Apr 27, 2021
1 parent 9da5d98 commit d9d0ce1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-route53/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const delegationRole = iam.Role.fromRoleArn(this, 'DelegationRole', delegationRo
new route53.CrossAccountZoneDelegationRecord(this, 'delegate', {
delegatedZone: subZone,
parentHostedZoneName: 'someexample.com', // or you can use parentHostedZoneId
delegationRole: delegationRole
delegationRole,
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
async function cfnEventHandler(props: ResourceProperties, isDeleteEvent: boolean) {
const { AssumeRoleArn, ParentZoneId, ParentZoneName, DelegatedZoneName, DelegatedZoneNameServers, TTL } = props;

if (!ParentZoneId && !ParentZoneName) {
throw Error('One of ParentZoneId or ParentZoneName must be specified');
}

const credentials = await getCrossAccountCredentials(AssumeRoleArn);
const route53 = new Route53({ credentials });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,24 @@ jest.mock('aws-sdk', () => {
beforeEach(() => {
mockStsClient.assumeRole.mockReturnThis();
mockRoute53Client.changeResourceRecordSets.mockReturnThis();
mockRoute53Client.listHostedZonesByName.mockReturnThis();
});

afterEach(() => {
jest.clearAllMocks();
});

test('throws error if both ParentZoneId and ParentZoneName are not provided', async () => {
// WHEN
const event = getCfnEvent({}, {
ParentZoneId: undefined,
ParentZoneName: undefined,
});

// THEN
await expect(invokeHandler(event)).rejects.toThrow(/One of ParentZoneId or ParentZoneName must be specified/);
});

test('throws error if getting credentials fails', async () => {
// GIVEN
mockStsClient.promise.mockResolvedValueOnce({ Credentials: undefined });
Expand All @@ -44,7 +56,7 @@ test('throws error if getting credentials fails', async () => {
});
});

test('calls create resouce record set with Upsert for Create event', async () => {
test('calls create resource record set with Upsert for Create event', async () => {
// GIVEN
mockStsClient.promise.mockResolvedValueOnce({ Credentials: { AccessKeyId: 'K', SecretAccessKey: 'S', SessionToken: 'T' } });
mockRoute53Client.promise.mockResolvedValueOnce({});
Expand All @@ -71,7 +83,7 @@ test('calls create resouce record set with Upsert for Create event', async () =>
});
});

test('calls create resouce record set with DELETE for Delete event', async () => {
test('calls create resource record set with DELETE for Delete event', async () => {
// GIVEN
mockStsClient.promise.mockResolvedValueOnce({ Credentials: { AccessKeyId: 'K', SecretAccessKey: 'S', SessionToken: 'T' } });
mockRoute53Client.promise.mockResolvedValueOnce({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "AssetParameters6f9976bda7bdc2299a222bcc607302200193ba5e1b77c22cc2bdca44414774acS3Bucket2194A765"
"Ref": "AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3Bucket200D9216"
},
"S3Key": {
"Fn::Join": [
Expand All @@ -168,7 +168,7 @@
"Fn::Split": [
"||",
{
"Ref": "AssetParameters6f9976bda7bdc2299a222bcc607302200193ba5e1b77c22cc2bdca44414774acS3VersionKey860C328E"
"Ref": "AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3VersionKey0E5C26F0"
}
]
}
Expand All @@ -181,7 +181,7 @@
"Fn::Split": [
"||",
{
"Ref": "AssetParameters6f9976bda7bdc2299a222bcc607302200193ba5e1b77c22cc2bdca44414774acS3VersionKey860C328E"
"Ref": "AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3VersionKey0E5C26F0"
}
]
}
Expand Down Expand Up @@ -242,17 +242,17 @@
}
},
"Parameters": {
"AssetParameters6f9976bda7bdc2299a222bcc607302200193ba5e1b77c22cc2bdca44414774acS3Bucket2194A765": {
"AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3Bucket200D9216": {
"Type": "String",
"Description": "S3 bucket for asset \"6f9976bda7bdc2299a222bcc607302200193ba5e1b77c22cc2bdca44414774ac\""
"Description": "S3 bucket for asset \"d17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602\""
},
"AssetParameters6f9976bda7bdc2299a222bcc607302200193ba5e1b77c22cc2bdca44414774acS3VersionKey860C328E": {
"AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602S3VersionKey0E5C26F0": {
"Type": "String",
"Description": "S3 key for asset version \"6f9976bda7bdc2299a222bcc607302200193ba5e1b77c22cc2bdca44414774ac\""
"Description": "S3 key for asset version \"d17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602\""
},
"AssetParameters6f9976bda7bdc2299a222bcc607302200193ba5e1b77c22cc2bdca44414774acArtifactHash2F5ADA6C": {
"AssetParametersd17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602ArtifactHash37FB4D0C": {
"Type": "String",
"Description": "Artifact hash for asset \"6f9976bda7bdc2299a222bcc607302200193ba5e1b77c22cc2bdca44414774ac\""
"Description": "Artifact hash for asset \"d17df4f90e07a972e8f7b00dddbae8e3eba45a212226d2b714dcd28dded69602\""
}
}
}

0 comments on commit d9d0ce1

Please sign in to comment.