Skip to content

Commit

Permalink
feat(custom-resource): Allow custom ResourceTypes on CustomResources (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored and mergify[bot] committed Dec 18, 2019
1 parent d855df1 commit c605ceb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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",
Expand Down Expand Up @@ -74,6 +75,7 @@ test('onCreate defaults to onUpdate', () => {

// WHEN
new AwsCustomResource(stack, 'AwsSdk', {
resourceType: 'Custom::S3PutObject',
onUpdate: {
service: 's3',
action: 'putObject',
Expand All @@ -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",
Expand Down Expand Up @@ -176,6 +178,7 @@ test('encodes booleans', () => {

// WHEN
new AwsCustomResource(stack, 'AwsSdk', {
resourceType: 'Custom::ServiceAction',
onCreate: {
service: 'service',
action: 'action',
Expand All @@ -190,7 +193,7 @@ test('encodes booleans', () => {
});

// THEN
expect(stack).toHaveResource('Custom::AWS', {
expect(stack).toHaveResource('Custom::ServiceAction', {
"Create": {
"service": "service",
"action": "action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Type": "AWS::SNS::Topic"
},
"Publish2E9BDF73": {
"Type": "Custom::AWS",
"Type": "Custom::SNSPublisher",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
Expand Down Expand Up @@ -194,7 +194,7 @@
}
},
"GetParameter42B0A00E": {
"Type": "Custom::AWS",
"Type": "Custom::SSMParameter",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit c605ceb

Please sign in to comment.