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.5k stars 3.84k forks source link

aws-cdk-lib/aws-ssm: StringListParameter (Error in FnJoin) #27810

Open anneadb opened 10 months ago

anneadb commented 10 months ago

Describe the bug

I added a StringListParameter to my existing Stack and suddenly get the following error:

Error: FnJoin requires at least one value to be provided
    at Function.join (/Users/path_to_my_git_repo/node_modules/aws-cdk-lib/core/lib/cfn-fn.js:1:1026)
    at new StringListParameter (/Users/path_to_my_git_repo/node_modules/aws-cdk-lib/aws-ssm/lib/parameter.js:1:13016)
    at EosAwsAccountMlBootstrapStack.setupVpc (/Users/path_to_my_git_repo/lib/eos-aws-account-ml-bootstrap-stack.ts:157:5)
    at new EosAwsAccountMlBootstrapStack (/Users/path_to_my_git_repo/lib/eos-aws-account-ml-bootstrap-stack.ts:42:10)
    at Object.<anonymous> (/Users/path_to_my_git_repo/bin/eos-aws-account-ml-bootstrap.ts:29:1)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module.m._compile (/Users/path_to_my_git_repo/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/path_to_my_git_repo/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1119:32)

Here is the code I added:

const vpc = ec2.Vpc.fromLookup(this, "Vpc", {
      vpcName: vpcName,
      subnetGroupNameTag: "type",
    })

const appSubnetGroupSelections = vpc.selectSubnets({
      subnetGroupName: "app",
    })

new cdk.aws_ssm.StringListParameter(this, "VpcParamSubnets", {
      parameterName: "/iac/vpc/appSubnetIds",
      stringListValue: appSubnetGroupSelections.subnetIds,
    })

Expected Behavior

Successfully synth and deploy stack.

Current Behavior

Cannot synth or deploy stack.

Reproduction Steps

For some reason this error only occurs in some AWS accounts but not in others so it may be hard to reproduce. We roll out this stack in 8 different accounts and I currently cannot tell why it fails in one account but not the others.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.103.1

Framework Version

No response

Node.js Version

v18.17.0

OS

MacOS Sonoma 14.1

Language

TypeScript

Language Version

No response

Other information

No response

anneadb commented 10 months ago

I think https://github.com/aws/aws-cdk/issues/21682 may be related

pahud commented 10 months ago

I can't reproduce this.

Are you able to print it in the CfnOutput like this?

new CfnOutput(this, 'SelectedSubnetIds', { value: appSubnetGroupSelections.subnetIds.join(',') })

And see the result like this?

Outputs:
demo.SelectedSubnetIds = subnet-071c85610846aa9c0,subnet-0ef7ac49e1edb06e4,subnet-0e2177a10a166f87d
github-actions[bot] commented 9 months ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

anneadb commented 9 months ago

Hi @pahud ,

yes, if I remove the StringListParameter and instead add the CfnOutput I can successfully run cdk diff and cdk synth:

new cdk.CfnOutput(this, "SelectedSubnetIds", {
      value: appSubnetGroupSelections.subnetIds.join(","),
    })

    // new cdk.aws_ssm.StringListParameter(this, "VpcParamSubnets", {
    //   parameterName: "/iac/vpc/appSubnetIds",
    //   stringListValue: appSubnetGroupSelections.subnetIds,
    // })

From the synth I see:

Outputs:
  SelectedSubnetIds:
    Value: subnet-12345someid,subnet-12345someid,subnet-12345someid
anneadb commented 9 months ago

Now this is really strange: If I add both the CfnOutput and StringListParameter then I can also synth the stack successfully. I have no idea why?

anneadb commented 9 months ago

But in another project I get the same error message in a completely different setup: I have three stacks in my app, stacks 1 and 2 are only deployed to one account but stack 3 is also deployed to other accounts. Stack 1 contains a StringListParameter. Whenever I try to deploy stack 3 in another account from stack 1 I get the same error message from above. If I uncomment stack 1 and 2 from the app then I can deploy stack 3 successfully. Could this be another hint for the source of the issue?

anneadb commented 9 months ago

I found this comment https://stackoverflow.com/a/73249828/10829644 indicating that sometime the cdk.context.json could cause issues with deployment. Could that be something? I tried removing this file but then none of my existing stacks sync anymore.

anneadb commented 9 months ago

Hi @pahud ,

any ideas for what else I can test? I am still seeing this issue and therefore cannot store any string lists - which would be really useful.