From 4458a4fc5bdf6efa419093f6eddd689803d6a328 Mon Sep 17 00:00:00 2001 From: Godwin Rose Samuel Date: Mon, 4 Mar 2024 13:51:15 -0800 Subject: [PATCH] update condition and readme --- packages/aws-cdk-lib/aws-autoscaling/README.md | 4 +++- .../aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/aws-cdk-lib/aws-autoscaling/README.md b/packages/aws-cdk-lib/aws-autoscaling/README.md index 82dbc584da9a2..ff03c316549ed 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/README.md +++ b/packages/aws-cdk-lib/aws-autoscaling/README.md @@ -542,7 +542,9 @@ property: [Custom termination policy](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lambda-custom-termination-policy.html) with lambda can be used to determine which instances to terminate based on custom logic. The custom termination policy can be specified using `TerminationPolicy.CUSTOM_LAMBDA_FUNCTION`. If this is -specified, you must also supply a value of lambda arn in the `terminationPolicyCustomLambdaFunctionArn` property. +specified, you must also supply a value of lambda arn in the `terminationPolicyCustomLambdaFunctionArn` property and +attach necessary [permission](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lambda-custom-termination-policy.html#lambda-custom-termination-policy-create-function) +to invoke the lambda function. If there are multiple termination policies specified, custom termination policy with lambda `TerminationPolicy.CUSTOM_LAMBDA_FUNCTION` diff --git a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts index a4d84ff846235..dee4d5b3a372a 100644 --- a/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts +++ b/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts @@ -1487,12 +1487,11 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements if (props.terminationPolicies) { props.terminationPolicies.forEach((terminationPolicy, index) => { if (terminationPolicy === TerminationPolicy.CUSTOM_LAMBDA_FUNCTION) { - if (index != 0) { + if (index !== 0) { throw new Error('TerminationPolicy.CUSTOM_LAMBDA_FUNCTION must be specified first in the termination policies'); } - if (!props.terminationPolicyCustomLambdaFunctionArn || - props.terminationPolicyCustomLambdaFunctionArn.length == 0) { + if (!props.terminationPolicyCustomLambdaFunctionArn) { throw new Error('terminationPolicyCustomLambdaFunctionArn property must be specified if the TerminationPolicy.CUSTOM_LAMBDA_FUNCTION is used'); }