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(ec2): choose NAT instance v2 machineImage cpuType automatically from instanceType #30558

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

tmokmss
Copy link
Contributor

@tmokmss tmokmss commented Jun 15, 2024

Issue # (if applicable)

n/a

Reason for this change

When configuring NAT instance v2, currently we have to set machineImage manually when we want to use a graviton instance.

Like this:

const vpc = new Vpc(this, 'Vpc', {
  natGatewayProvider: NatProvider.instanceV2({
    instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO),
    // we should be able to omit this line!
    machineImage: MachineImage.latestAmazonLinux2023({ cpuType: AmazonLinuxCpuType.ARM_64 }),
  }),
});

This can be easily avoided if Nat instance v2 construct decides which cpu type to use for the given instance type.

Description of changes

Use instanceType.architecture to choose cpu type of a machine image.

Now we can remove the redundant code:

const vpc = new Vpc(this, 'Vpc', {
  natGatewayProvider: NatProvider.instanceV2({
    instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO),
  }),
});

Description of how you validated changes

Added an integ test.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the p2 label Jun 15, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team June 15, 2024 16:20
@github-actions github-actions bot added the star-contributor [Pilot] contributed between 25-49 PRs to the CDK label Jun 15, 2024
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 15, 2024
Copy link
Contributor

@GavinZZ GavinZZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is something we should have thought of on the intial implementation. But updating it now would potentially be a breaking change due to x86 and arm compatibilities issues. Correct me if wrong but existing users who specified arm_64 instance type are actually using x86 type. Now if we allow this change, their instance is going to be updated with arm_64 instance type and may be breaking change.

If this is correct, I would recommend you putting this fix under feature flag.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 20, 2024
@tmokmss
Copy link
Contributor Author

tmokmss commented Jun 21, 2024

@GavinZZ Fortunately, no, it is not a breaking change, because we cannot deploy arm instance with x86 AMIs due to the mismatch of architecture. We get the following error during a deployment:

Resource handler returned message: "The architecture 'arm64' of the specified instance type does not match the architecture 'x86_64' of the specified AMI. Specify an instance type and an AMI
that have matching architectures, and try again. You can use 'describe-instance-types' or 'describe-images' to discover the architecture of the instance type or AMI. (Service: Ec2, Status Co
de: 400,

@GavinZZ
Copy link
Contributor

GavinZZ commented Jun 21, 2024

@GavinZZ Fortunately, no, it is not a breaking change, because we cannot deploy arm instance with x86 AMIs due to the mismatch of architecture. We get the following error during a deployment:

Resource handler returned message: "The architecture 'arm64' of the specified instance type does not match the architecture 'x86_64' of the specified AMI. Specify an instance type and an AMI
that have matching architectures, and try again. You can use 'describe-instance-types' or 'describe-images' to discover the architecture of the instance type or AMI. (Service: Ec2, Status Co
de: 400,

Thanks for clarification,I'm good to approve in this case.

Copy link
Contributor

mergify bot commented Jun 21, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: d5a6ada
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit f93c2ef into aws:main Jun 21, 2024
9 checks passed
Copy link
Contributor

mergify bot commented Jun 21, 2024

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@tmokmss tmokmss deleted the natinstacev2-arm branch June 21, 2024 01:48
sarangarav pushed a commit to sarangarav/aws-cdk that referenced this pull request Jun 21, 2024
… from instanceType (aws#30558)

### Issue # (if applicable)
n/a

### Reason for this change

When configuring NAT instance v2, currently we have to set machineImage manually when we want to use a graviton instance.

Like this:

```ts
const vpc = new Vpc(this, 'Vpc', {
  natGatewayProvider: NatProvider.instanceV2({
    instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO),
    // we should be able to omit this line!
    machineImage: MachineImage.latestAmazonLinux2023({ cpuType: AmazonLinuxCpuType.ARM_64 }),
  }),
});
```

This can be easily avoided if Nat instance v2 construct decides which cpu type to use for the given instance type.

### Description of changes

Use `instanceType.architecture` to choose cpu type of a machine image.

Now we can remove the redundant code:

```ts
const vpc = new Vpc(this, 'Vpc', {
  natGatewayProvider: NatProvider.instanceV2({
    instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO),
  }),
});
```

### Description of how you validated changes

Added an integ test.
### Checklist
- [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/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*
mazyu36 pushed a commit to mazyu36/aws-cdk that referenced this pull request Jun 22, 2024
… from instanceType (aws#30558)

### Issue # (if applicable)
n/a

### Reason for this change

When configuring NAT instance v2, currently we have to set machineImage manually when we want to use a graviton instance.

Like this:

```ts
const vpc = new Vpc(this, 'Vpc', {
  natGatewayProvider: NatProvider.instanceV2({
    instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO),
    // we should be able to omit this line!
    machineImage: MachineImage.latestAmazonLinux2023({ cpuType: AmazonLinuxCpuType.ARM_64 }),
  }),
});
```

This can be easily avoided if Nat instance v2 construct decides which cpu type to use for the given instance type.

### Description of changes

Use `instanceType.architecture` to choose cpu type of a machine image.

Now we can remove the redundant code:

```ts
const vpc = new Vpc(this, 'Vpc', {
  natGatewayProvider: NatProvider.instanceV2({
    instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO),
  }),
});
```

### Description of how you validated changes

Added an integ test.
### Checklist
- [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/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*
@aws-cdk-automation
Copy link
Collaborator

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.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants