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(stepfunctions-tasks): migrate eval-nodejs handler #27840

Merged
merged 6 commits into from
Nov 17, 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.

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
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
Loading