検証環境等で、不必要になった ECS タスク定義を全部消すためのワンライナー

検証用のアカウントで、ECS のタスク定義として大量に INACTIVE のものが溜まっていたので削除しようと思いワンライナー

for taskdef in $(aws ecs list-task-definitions --status INACTIVE --query "taskDefinitionArns"| jq ".[]" -r | cut -d'/' -f2); do aws ecs delete-task-definitions --task-definitions $taskdef ; done

CDK の CfnAssociation でハマったところ

AWS CDK (typescript) で AWS Managed MSAD を立てて、同一 CDK 内で SSM ステートマネージャーへのアソシエーションによって EC2 インスタンスドメイン参加させようとしたのだが、 SSM の AWS-JoinDirectoryServiceDomain ドキュメントに記載されている通りに parameter のうち directoryId directoryName の型を String に合わせると、

CfnSynthesisError: Resolution error: Supplied properties not correct for "CfnAssociationProps"
  parameters: element 'directoryName': "corp.xxxxxxxxx.com" should be an 'object'.

というエラーが発生して Synthesis が通らなくてハマった。

下のように、当該の2つのパラメータを [] で囲んだら動くようになった。

    const ad = new CfnMicrosoftAD(this, "MSAD", {
      name: "corp.xxxxxxxxx.com",
      edition: "Standard",
      password: "xxxxxxxxxxx",
      vpcSettings: {
        subnetIds: vpc.selectSubnets({ subnetType: SubnetType.PRIVATE_WITH_NAT }).subnetIds,
        vpcId: vpc.vpcId
      },
    });
    // ... 中略
    new CfnAssociation(this, "SsmAssociation", {
      name: "AWS-JoinDirectoryServiceDomain",
      associationName: "JoinDomainFSxTestStack",
      parameters: {
        "directoryId": [ad.attrAlias],
        "dnsIpAddresses": ad.attrDnsIpAddresses,
        "directoryName": ["corp.xxxxxxxxx.com"]
      },
      targets: [{
        key: "InstanceIds",
        values: [ec2_instance.instanceId]
      }],
    })