Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(custom-resources): AwsResource - support custom resource type #5248

Merged
merged 2 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Expand Up @@ -269,4 +269,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 @@ -36,6 +37,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