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_ecs: ec2Service placement strategies use incorrect casing which causes drift #20812

Closed
tea-418 opened this issue Jun 21, 2022 · 2 comments · Fixed by #20946
Closed

aws_ecs: ec2Service placement strategies use incorrect casing which causes drift #20812

tea-418 opened this issue Jun 21, 2022 · 2 comments · Fixed by #20946
Assignees
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@tea-418
Copy link
Contributor

tea-418 commented Jun 21, 2022

Describe the bug

When adding the packedByCpu() PlacementStrategy to a new ecs service, the cf template generated has the Property

"PlacementStrategies": [{
    "Field": "cpu",
    "Type": "binpack"
}]

However this will cause the Stack to drift as CF only allows CPU spelled in uppercase.
See here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-service-placementstrategy.html

Expected Behavior

CDK should generate the "Field" attribute of "PlacementStrategies" according to CF demands.

In the CF Template PlacementStrategies should look like this:

"PlacementStrategies": [{
    "Field": "CPU",
    "Type": "binpack"
}],

Current Behavior

CDK generates the "Field" attribute of "PlacementStrategies" NOT according to CF demands but instead spells it in lowercase.

In the CF Template PlacementStrategies actually looks like this:

"PlacementStrategies": [{
    "Field": "cpu",
     "Type": "binpack"
}],

Reproduction Steps

  1. Generate a fresh cdk project with cdk init app --language=typescript -j

  2. in the lib/project-name-stack.ts add a ecs service to a cluster with the PlacementStrategy set:

import { aws_ecs, aws_ec2, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';

export class VanillaCdkStack extends Stack {
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    const vpc = new aws_ec2.Vpc(this, 'Vpc', { maxAzs: 2 });

    const cluster = new aws_ecs.Cluster(this, 'EcsCluster', { vpc });
    cluster.addCapacity('DefaultAutoScalingGroup', {
      instanceType: aws_ec2.InstanceType.of(aws_ec2.InstanceClass.T2, aws_ec2.InstanceSize.MICRO)
    });

    const taskDefinition = new aws_ecs.Ec2TaskDefinition(this, 'TaskDef');
    const container = taskDefinition.addContainer('web', {
      image: aws_ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
      memoryLimitMiB: 256,
    });

    const service = new aws_ecs.Ec2Service(this, "Test_Stack",{
      cluster,
      taskDefinition,
      placementStrategies: [
        aws_ecs.PlacementStrategy.packedByCpu(), // <--- here
      ]
    });
  }
}
  1. run cdk synth

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.28.1 (build d035432)

Framework Version

No response

Node.js Version

v16.14.2

OS

Windows 10 Enterprise 21H2

Language

Typescript

Language Version

No response

Other information

No response

@tea-418 tea-418 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 21, 2022
@github-actions github-actions bot added the @aws-cdk/aws-ecs Related to Amazon Elastic Container label Jun 21, 2022
@peterwoodworth peterwoodworth added p1 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 5, 2022
@peterwoodworth
Copy link
Contributor

Thanks for reporting this @tea-418, someone should be able to look at the PR soon

@peterwoodworth peterwoodworth changed the title aws_ecs.Ec2Service: aws_ecs_PlacementStrategy.packedByCpu() generating faulty CF Template aws_ecs: ec2Service placement strategies use incorrect casing which causes drift Jul 7, 2022
@mergify mergify bot closed this as completed in #20946 Jul 30, 2022
mergify bot pushed a commit that referenced this issue Jul 30, 2022
…causes drift (#20946)

Fixes #20812 

Switches lowercase cpu and memory placement strategy to uppercase as required by cloudformation:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-service-placementstrategy.html

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

josephedward pushed a commit to josephedward/aws-cdk that referenced this issue Aug 30, 2022
…causes drift (aws#20946)

Fixes aws#20812 

Switches lowercase cpu and memory placement strategy to uppercase as required by cloudformation:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-service-placementstrategy.html

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs Related to Amazon Elastic Container bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants