Skip to content

Commit

Permalink
chore(stepfunctions-tasks): migrate eval-nodejs handler (#27840)
Browse files Browse the repository at this point in the history
This PR moves the eval-nodejs handler from aws-cdk-lib to our new centralized location for custom resource handlers in the [@aws-cdk](https://github.com/aws-cdk) package.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
colifran authored Nov 17, 2023
1 parent 0607b2c commit ff20d6b
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 48 deletions.

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.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "4a61519d8f4df8206cfaff4e519462aa81beab9213c3642a1353cd679c697638.zip"
"S3Key": "b8cec122f25692e8b194663d25a2ee5e0b65e55df966120791d6a3ddc08fc136.zip"
},
"Handler": "index.handler",
"Role": {
Expand Down Expand Up @@ -91,7 +91,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "4a61519d8f4df8206cfaff4e519462aa81beab9213c3642a1353cd679c697638.zip"
"S3Key": "b8cec122f25692e8b194663d25a2ee5e0b65e55df966120791d6a3ddc08fc136.zip"
},
"Handler": "index.handler",
"Role": {
Expand Down

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
@@ -1,5 +1,21 @@
/* eslint-disable no-console */
import { Event } from '../evaluate-expression';

/**
* The event received by the Lambda function
*
* @internal
*/
export interface Event {
/**
* The expression to evaluate
*/
readonly expression: string;

/**
* The expression attribute values
*/
readonly expressionAttributeValues: { [key: string]: any };
}

function escapeRegex(x: string) {
return x.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
Expand All @@ -15,5 +31,6 @@ export async function handler(event: Event): Promise<any> {
);
console.log(`Expression: ${expression}`);

return eval(expression);
// direct eval with bundler is not recommended - using indirect eval
return [eval][0](expression);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Event } from '../lib';
import { handler } from '../lib/eval-nodejs-handler';
import { handler, Event } from '../../lib/aws-stepfunctions-tasks/eval-nodejs-handler';

beforeAll(() => {
jest.spyOn(console, 'log').mockImplementation();
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface EvaluateExpressionProps extends sfn.TaskStateBaseProps {
/**
* The event received by the Lambda function
*
* Shared definition with packages/@aws-cdk/custom-resource-handlers/lib/custom-resources/aws-stepfunctions-tasks/index.ts
*
* @internal
*/
export interface Event {
Expand Down Expand Up @@ -119,7 +121,7 @@ function createEvalFn(runtime: lambda.Runtime | undefined, scope: Construct) {
uuid,
handler: 'index.handler',
lambdaPurpose,
code: lambda.Code.fromAsset(path.join(__dirname, 'eval-nodejs-handler'), {
code: lambda.Code.fromAsset(path.join(__dirname, '..', '..', 'custom-resource-handlers', 'dist', 'aws-stepfunctions-tasks', 'eval-nodejs-handler'), {
exclude: ['*.ts'],
}),
});
Expand Down

0 comments on commit ff20d6b

Please sign in to comment.