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

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

Open
Xfel opened this issue May 3, 2024 · 2 comments · May be fixed by #31446
Open

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

Xfel opened this issue May 3, 2024 · 2 comments · May be fixed by #31446
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@Xfel
Copy link

Xfel commented May 3, 2024

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

@Xfel Xfel added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 3, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label May 3, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-triage This issue or PR still needs to be triaged. labels May 3, 2024
@khushail
Copy link
Contributor

khushail commented May 3, 2024

Thanks @Xfel for pointing this and sharing the repro code. I can see the value is being overwritte.

private applyUpdatePolicies(props: InstanceProps) {

Marking the issue as appropriate.

@khushail khushail added p2 effort/small Small work item – less than a day of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels May 3, 2024
@msambol
Copy link
Contributor

msambol commented May 5, 2024

I can take this. Do we want to choose the maximum of the two or throw an error if both are supplied?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants