From c605ceb40a49528505669bac61403673b38da5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB=E0=A5=8D?= =?UTF-8?q?=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95=E0=A5=8D?= =?UTF-8?q?=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 18 Dec 2019 14:33:29 +0100 Subject: [PATCH] feat(custom-resource): Allow custom ResourceTypes on CustomResources (#5248) --- .../lib/aws-custom-resource/aws-custom-resource.ts | 9 ++++++++- .../test/aws-custom-resource/aws-custom-resource.test.ts | 9 ++++++--- .../integ.aws-custom-resource.expected.json | 4 ++-- .../aws-custom-resource/integ.aws-custom-resource.ts | 2 ++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts b/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts index 56b5f63a581a9..b9aff923d5875 100644 --- a/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts +++ b/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts @@ -99,6 +99,13 @@ export interface AwsSdkCall { } export interface AwsCustomResourceProps { + /** + * Cloudformation Resource type. + * + * @default - Custom::AWS + */ + readonly resourceType?: string; + /** * The AWS SDK call to make when the resource is created. * At least onCreate, onUpdate or onDelete must be specified. @@ -200,7 +207,7 @@ export class AwsCustomResource extends cdk.Construct implements iam.IGrantable { const create = props.onCreate || props.onUpdate; this.customResource = new CustomResource(this, 'Resource', { - resourceType: 'Custom::AWS', + resourceType: props.resourceType || 'Custom::AWS', provider: CustomResourceProvider.fromLambda(provider), properties: { create: create && encodeBooleans(create), diff --git a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts index 87ded6b98cce3..e19bdcc6bcf58 100644 --- a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts +++ b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts @@ -11,6 +11,7 @@ test('aws sdk js custom resource with onCreate and onDelete', () => { // WHEN new AwsCustomResource(stack, 'AwsSdk', { + resourceType: 'Custom::LogRetentionPolicy', onCreate: { service: 'CloudWatchLogs', action: 'putRetentionPolicy', @@ -30,7 +31,7 @@ test('aws sdk js custom resource with onCreate and onDelete', () => { }); // THEN - expect(stack).toHaveResource('Custom::AWS', { + expect(stack).toHaveResource('Custom::LogRetentionPolicy', { "Create": { "service": "CloudWatchLogs", "action": "putRetentionPolicy", @@ -74,6 +75,7 @@ test('onCreate defaults to onUpdate', () => { // WHEN new AwsCustomResource(stack, 'AwsSdk', { + resourceType: 'Custom::S3PutObject', onUpdate: { service: 's3', action: 'putObject', @@ -87,7 +89,7 @@ test('onCreate defaults to onUpdate', () => { }); // THEN - expect(stack).toHaveResource('Custom::AWS', { + expect(stack).toHaveResource('Custom::S3PutObject', { "Create": { "service": "s3", "action": "putObject", @@ -176,6 +178,7 @@ test('encodes booleans', () => { // WHEN new AwsCustomResource(stack, 'AwsSdk', { + resourceType: 'Custom::ServiceAction', onCreate: { service: 'service', action: 'action', @@ -190,7 +193,7 @@ test('encodes booleans', () => { }); // THEN - expect(stack).toHaveResource('Custom::AWS', { + expect(stack).toHaveResource('Custom::ServiceAction', { "Create": { "service": "service", "action": "action", diff --git a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.expected.json b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.expected.json index f7bc469e9b2b4..ab76c0e4ed247 100644 --- a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.expected.json +++ b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.expected.json @@ -4,7 +4,7 @@ "Type": "AWS::SNS::Topic" }, "Publish2E9BDF73": { - "Type": "Custom::AWS", + "Type": "Custom::SNSPublisher", "Properties": { "ServiceToken": { "Fn::GetAtt": [ @@ -194,7 +194,7 @@ } }, "GetParameter42B0A00E": { - "Type": "Custom::AWS", + "Type": "Custom::SSMParameter", "Properties": { "ServiceToken": { "Fn::GetAtt": [ diff --git a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.ts b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.ts index 57400f4d99db2..7d709691491e3 100644 --- a/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.ts +++ b/packages/@aws-cdk/custom-resources/test/aws-custom-resource/integ.aws-custom-resource.ts @@ -11,6 +11,7 @@ const stack = new cdk.Stack(app, 'aws-cdk-sdk-js'); const topic = new sns.Topic(stack, 'Topic'); const snsPublish = new AwsCustomResource(stack, 'Publish', { + resourceType: 'Custom::SNSPublisher', onUpdate: { service: 'SNS', action: 'publish', @@ -35,6 +36,7 @@ const ssmParameter = new ssm.StringParameter(stack, 'DummyParameter', { stringValue: '1337', }); const getParameter = new AwsCustomResource(stack, 'GetParameter', { + resourceType: 'Custom::SSMParameter', onUpdate: { service: 'SSM', action: 'getParameter',