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

(cli): ECS hotswap breaks Firelens configuration #21692

Closed
tmokmss opened this issue Aug 21, 2022 · 1 comment · Fixed by #21748
Closed

(cli): ECS hotswap breaks Firelens configuration #21692

tmokmss opened this issue Aug 21, 2022 · 1 comment · Fixed by #21748
Assignees
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. package/tools Related to AWS CDK Tools or CLI

Comments

@tmokmss
Copy link
Contributor

tmokmss commented Aug 21, 2022

Describe the bug

When I hotswap ECS service with the below Firelens configuration, the deployment fails because it seems options.Name is implicitly converted to options.name during hotswap.

      logging: LogDrivers.firelens({
        options: {
          Name: 'cloudwatch',
          region: Stack.of(this).region,
          log_group_name: logGroup.logGroupName,
          log_stream_prefix: 'prefix',
        },
      }),

Expected Behavior

Hotswap deployment successes just like CFn deployment.

Current Behavior

After hotswap, the fluentbit container failed to start with the following stoppedReason:

Stopped reason InternalError: unable to generate fireLens config file: unable to generate fireLens config content: unable to generate fluent config output section: unable to apply log options of container Main to fireLens config: missing output key Name which is required for fireLens configuration of type fluentbit

Reproduction Steps

  1. deploy the stack below
  2. change fromRegistry('nginx') to fromRegistry('nginx:latest') to trigger hotswap
  3. run cdk deploy --hotswap
  4. hotswap gets stuck. Checking management console, you can see the error above.
import * as cdk from 'aws-cdk-lib';
import { SubnetType, Vpc } from 'aws-cdk-lib/aws-ec2';
import { Cluster } from 'aws-cdk-lib/aws-ecs';
import { RemovalPolicy, Stack } from 'aws-cdk-lib';
import {
  ContainerImage,
  FargateService,
  FargateTaskDefinition,
  FirelensLogRouterType,
  LogDrivers,
} from 'aws-cdk-lib/aws-ecs';
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
import { Construct } from 'constructs';

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

    const vpc = new Vpc(this, 'Vpc', {
      subnetConfiguration: [
        {
          cidrMask: 20,
          name: 'public',
          subnetType: SubnetType.PUBLIC,
        },
      ],
    });

    const cluster = new Cluster(this, 'Cluster', {
      vpc,
    });

    const logGroup = new LogGroup(this, 'ExecutionLog', {
      retention: RetentionDays.SIX_MONTHS,
      removalPolicy: RemovalPolicy.DESTROY,
    });

    const taskDefinition = new FargateTaskDefinition(this, 'TaskDef', {
      memoryLimitMiB: 512,
      cpu: 256,
    });

    taskDefinition.addContainer('Main', {
      image: ContainerImage.fromRegistry('nginx'),
      logging: LogDrivers.firelens({
        options: {
          Name: 'cloudwatch',
          region: Stack.of(this).region,
          log_group_name: logGroup.logGroupName,
          log_stream_prefix: 'main',
        },
      }),
    });

    taskDefinition.addFirelensLogRouter('Firelens', {
      firelensConfig: {
        type: FirelensLogRouterType.FLUENTBIT,
      },
      image: ContainerImage.fromRegistry('amazon/aws-for-fluent-bit'),
      logging: LogDrivers.awsLogs({
        streamPrefix: 'firelens',
        logGroup,
      }),
    });

    const service = new FargateService(this, 'Default', {
      cluster,
      taskDefinition,
      assignPublicIp: true,
    });
  }
}

Possible Solution

This line seems to be the root cause of this problem.

const lowercasedTaskDef = transformObjectKeys(this.taskDefinitionResource, lowerCaseFirstCharacter);
const registerTaskDefResponse = await sdk.ecs().registerTaskDefinition(lowercasedTaskDef).promise();

There are several properties in the RegisterTaskDefinition request that take arbitrary string as a property key, such as dockerLabels , logConfiguration.options, or dockerVolumeConfiguration.labels in addition to firelensConfiguration.options. We must not lowercase those property keys selectively.

Additional Information/Context

No response

CDK CLI Version

2.38.1

Framework Version

2.38.1

Node.js Version

16.15.0

OS

macOS

Language

Typescript

Language Version

No response

Other information

No response

@tmokmss tmokmss added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 21, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Aug 21, 2022
@mergify mergify bot closed this as completed in #21748 Aug 25, 2022
mergify bot pushed a commit that referenced this issue Aug 25, 2022
closes #21692 

Now we can specify keys that will not be transformed by `transformObjectKeys` function.

----

### 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
closes aws#21692 

Now we can specify keys that will not be transformed by `transformObjectKeys` function.

----

### 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
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants