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

Closed
Xfel opened this issue May 3, 2024 · 4 comments · Fixed by #31446 · May be fixed by ajobayer/aws-secure-environment-accelerator#4
Closed
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:/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?

Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

1 similar comment
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2024
HBobertz pushed a commit that referenced this issue Sep 24, 2024
…ut (#31446)

### Issue # (if applicable)

Closes #30052 

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

### Description of changes
- If both `initOptions.timeout` and `resourceSignalTimeout` are set, timeout consisting of the sum of the values and a warning suggesting that only one field should be specified
- Else, timeout is set to field specified, else defaults to 5 min

### Description of how you validated changes
- Update integration test for `instance-init.js` with both fields and verify that warning is logged
- Add unit tests:
  - `initOptions.timeout` and `resourceSignalTimeout` are both not set, timeout is set to default of 5 min
  - `initOptions.timeout` set and `resourceSignalTimeout` not set, timeout is set to initOptions.timeout
  - `initOptions.timeout` not set and `resourceSignalTimeout` is set, timeout is set to `resourceSignalTimeout`
  - `initOptions.timeout` and `resourceSignalTimeout` are both set, timeout is set to sum of timeouts and warning is logged

### Checklist
- [ ] My code adheres to the [CONTRIBUTING GUIDE](https:/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https:/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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
4 participants