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

chore(core): migrate cfn-utils handler #27904

Merged
merged 7 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "3e61d858eaa7724170872a455b8f788d5fcf18adba89aadbe603a52dab59d917.zip"
"S3Key": "f58e5b0009fc349d5e78d41594373bd6723e705a3c961a42adfbefa36cbe1bcf.zip"
},
"Timeout": 900,
"MemorySize": 128,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import { CfnUtilsResourceType } from './consts';
/**
* Supported resource type.
*/
export enum CfnUtilsResourceType {
/**
* CfnJson
*/
CFN_JSON = 'Custom::AWSCDKCfnJson',

/**
* CfnJsonStringify
*/
CFN_JSON_STRINGIFY = 'Custom::AWSCDKCfnJsonStringify',
}

/**
* Parses the value of "Value" and reflects it back as attribute.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CfnUtilsResourceType } from '../../lib/private/cfn-utils-provider/consts';
import { handler } from '../../lib/private/cfn-utils-provider/index';
import { handler, CfnUtilsResourceType } from '../../lib/core/cfn-utils-provider/index';

test('parses value as JSON', async () => {
// GIVEN
Expand Down Expand Up @@ -67,6 +66,17 @@ test('fails if wrong resource type', async () => {
await expect(() => invokeHandler(event)).rejects.toThrow(/unexpected resource type "Create"/);
});

test('resource provider simply parses json and reflects back as an attribute', async () => {
const input = { foo: 1234 };
const response = await handler({
ResourceType: CfnUtilsResourceType.CFN_JSON,
ResourceProperties: {
Value: JSON.stringify(input),
},
} as any);
expect(input).toEqual(response.Data.Value);
});

// helper function to get around TypeScript expecting a complete event object,
// even though our tests only need some of the fields
async function invokeHandler(event: Partial<AWSLambda.CloudFormationCustomResourceEvent>) {
Expand Down
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/core/lib/private/cfn-utils-provider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as path from 'path';
import { Construct } from 'constructs';
import { CfnUtilsResourceType } from './cfn-utils-provider/consts';
import { CustomResource } from '../custom-resource';
Expand All @@ -10,7 +11,7 @@ export class CfnUtilsProvider extends Construct {
public static getOrCreate(scope: Construct) {
return CustomResourceProvider.getOrCreate(scope, 'AWSCDKCfnUtilsProvider', {
runtime: CustomResourceProviderRuntime.NODEJS_18_X,
codeDirectory: `${__dirname}/cfn-utils-provider`,
codeDirectory: path.join(__dirname, '..', '..', '..', 'custom-resource-handlers', 'dist', 'core', 'cfn-utils-provider'),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Shared definition with packages/@aws-cdk/custom-resource-handlers/lib/core/cfn-utils-provider/index.ts
/**
* Supported resource type.
*/
Expand Down
13 changes: 0 additions & 13 deletions packages/aws-cdk-lib/core/test/cfn-json.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { App, CfnResource, Lazy, Stack } from '../lib';
import { CfnJson } from '../lib/cfn-json';
import { CfnUtilsResourceType } from '../lib/private/cfn-utils-provider/consts';
import { handler } from '../lib/private/cfn-utils-provider/index';

describe('cfn json', () => {

Expand Down Expand Up @@ -71,15 +69,4 @@ describe('cfn json', () => {
'Fn::Join': ['', ['"{"ref=', { Ref: 'MyResource' }, '":"this is a I am lazy"}"']],
});
});

test('resource provider simply parses json and reflects back as an attribute', async () => {
const input = { foo: 1234 };
const response = await handler({
ResourceType: CfnUtilsResourceType.CFN_JSON,
ResourceProperties: {
Value: JSON.stringify(input),
},
} as any);
expect(input).toEqual(response.Data.Value);
});
});
Loading