aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.41k stars 3.8k forks source link

(ecs-patterns): ScheduledFargateTask - runtime platform ignored #27446

Open daniellorenzin opened 9 months ago

daniellorenzin commented 9 months ago

Describe the bug

The runtime platform on the pattern top level is getting ignored when set, for example as LINUX ARM64.

const scheduledTask = new ecsPatterns.ScheduledFargateTask(this, 'ScheduledTask', {
            cluster: cluster,
            schedule: Schedule.expression('cron(*/1 * * * ? *)'),
            subnetSelection: subnetsSelection,
            scheduledFargateTaskImageOptions: {
                image: ecs.ContainerImage.fromDockerImageAsset(dockerAsset),
                memoryLimitMiB: 512,
                cpu: 256,
                command: ['python', 'manage.py'],
                logDriver: new ecs.AwsLogDriver({streamPrefix: 'ScheduledTask'}),
                environment: {
                    DEBUG: "1",
                },
                secrets: {
                    ...secrets,
                },
            },
            runtimePlatform: {
                cpuArchitecture: ecs.CpuArchitecture.ARM64,
                operatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
            },
        });

Expected Behavior

The task definition should have the image arch set to LINUX/ARM64

Current Behavior

The task definition should have the image arch is not set. Therefore defaults to LINUX/X86_64 during deployment

Reproduction Steps

const scheduledTask = new ecsPatterns.ScheduledFargateTask(this, 'ScheduledTask', {
            cluster: cluster,
            schedule: Schedule.expression('cron(*/1 * * * ? *)'),
            subnetSelection: subnetsSelection,
            scheduledFargateTaskImageOptions: {
                image: ecs.ContainerImage.fromDockerImageAsset(dockerAsset),
                memoryLimitMiB: 512,
                cpu: 256,
                command: ['python', 'manage.py'],
                logDriver: new ecs.AwsLogDriver({streamPrefix: 'ScheduledTask'}),
                environment: {
                    DEBUG: "1",
                },
                secrets: {
                    ...secrets,
                },
            },
            runtimePlatform: {
                cpuArchitecture: ecs.CpuArchitecture.ARM64,
                operatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
            },
        });

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.100

Framework Version

No response

Node.js Version

20.8

OS

Mac

Language

TypeScript

Language Version

No response

Other information

No response

pahud commented 9 months ago

https://github.com/aws/aws-cdk/blob/6c34c9a75c513d629595fd30c3a2be3b64d69d68/packages/aws-cdk-lib/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts#L105-L114

This essentially renders the ecs parameters for events rule target, but looks like EcsParameters in CFN does not allow to specify runtimePlatform or CpuArchitecture? https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-ecsparameters.html

daniellorenzin commented 9 months ago

I ended up working around the issue, by splitting up the task defination and putting the runtimePlatform settings on that and it deployed and runs as expected.

        const taskDefinitionScheduled = new ecs.FargateTaskDefinition(this, 'TaskSchDef', {
            memoryLimitMiB: 1024,
            cpu: 512,
            runtimePlatform: {
                cpuArchitecture: ecs.CpuArchitecture.ARM64,
                operatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
            },
        });
        const containerScheduled = taskDefinitionScheduled.addContainer('ScheduledContainer', {
            image: ecs.ContainerImage.fromDockerImageAsset(asset),
            containerName: 'djangoScheduled',
            command: ['python', 'manage.py'],
            environment: {
                DEBUG: "1",
            },
            secrets: {
                ...secrets
            },
            logging: new ecs.AwsLogDriver({ streamPrefix: 'ShovelTask' }),
        });
        const scheduledTask = new ecsPatterns.ScheduledFargateTask(this, 'ScheduledTask', {
            cluster: cluster,
            schedule: Schedule.expression('cron(*/1 * * * ? *)'),
            subnetSelection: subnetsSelection,
            scheduledFargateTaskDefinitionOptions: {
                taskDefinition: taskDefinitionScheduled,
            },
        });