Skip to content

(aws-ec2): Instance resourceSignalTimeout overwrites initOptions.timeout #30052

@Xfel

Description

@Xfel

Describe the bug

When specifiying both resourceSignalTimeout and initOptions.timeout in the options for creating an EC2 Instance, only the value from resourceSignalTimeout is used.

Expected Behavior

A timeout consisting of the sum of the values, or a clear error that specifying both fields is not supported.

Current Behavior

resourceSignalTimeout overrides initOptions.timeout completely.

Reproduction Steps

In a new CDK project:

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';

export class CdkStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
	
	const vpc = ec2.Vpc.fromLookup(this, "VPC", {
      isDefault: true,
    });

    new ec2.Instance(this, 'Instance', {
      instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.SMALL),
      machineImage: ec2.MachineImage.latestWindows(ec2.WindowsVersion.WINDOWS_SERVER_2019_ENGLISH_FULL_BASE),
	  vpc,
      init: ec2.CloudFormationInit.fromElements(
        ec2.InitCommand.shellCommand('echo "Hello World"'),
      ),
      initOptions: {
        timeout: cdk.Duration.minutes(20),
      },
	  resourceSignalTimeout: cdk.Duration.minutes(20),
	})
  }
}

The resulting template lists for the instance:

    CreationPolicy:
      ResourceSignal:
        Timeout: PT10M

Possible Solution

In https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-ec2/lib/instance.ts, initOptions.timeout is applied before resourceSignalTimeout. The code to apply initOptions.timeout adds it to any preexisting timeout. Swapping the order of setup here should fix the issue.

Additional Information/Context

No response

CDK CLI Version

2.136.0 (build 94fd33b)

Framework Version

No response

Node.js Version

v18.18.0

OS

Windows

Language

TypeScript

Language Version

5.0.4

Other information

No response

Metadata

Metadata

Labels

@aws-cdk/aws-ec2Related to Amazon Elastic Compute CloudbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions