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

Automatic token exports can not be arrays #5897

Closed
nunezro2 opened this issue Jan 21, 2020 · 17 comments
Closed

Automatic token exports can not be arrays #5897

nunezro2 opened this issue Jan 21, 2020 · 17 comments
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/medium Medium work item – several days of effort p2

Comments

@nunezro2
Copy link

nunezro2 commented Jan 21, 2020

Reproduction Steps

Add the following to your stack:

Fn.select(0, vpcEndpoint.vpcEndpointDnsEntries)

It generates the following which is incorrect since DnsEntries are a string

"ExportsOutputFnGetAttVPCVpcCloudAuthVpcEndpointA6A0016BDnsEntries65E2739D": {
  "Value": {
    "Fn::GetAtt": [
      "VPCVpcCloudAuthVpcEndpointA6A0016B",
      "DnsEntries"
    ]
  },
  "Export": {
    "Name": "Vpc:ExportsOutputFnGetAttVPCVpcCloudAuthVpcEndpointA6A0016BDnsEntries65E2739D"
  }
}

Error Log

Vpc: creating CloudFormation changeset...

 ❌  Vpc failed: Error [ValidationError]: Template format error: The Value field of every Outputs member must evaluate to a String.
    at Request.extractError (/home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/protocol/query.js:50:29)
    at Request.callListeners (/home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/request.js:683:14)
    at Request.transition (/home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/request.js:685:12)
    at Request.callListeners (/home/linuxbrew/.linuxbrew/Cellar/aws-cdk/1.20.0/libexec/lib/node_modules/aws-cdk/node_modules/aws-sdk/lib/sequential_executor.js:116:18) {
  message: 'Template format error: The Value field of every Outputs member must evaluate to a String.',
  code: 'ValidationError',
  time: 2020-01-19T23:30:22.007Z,
  requestId: '43c10843-42a8-4439-a770-a77ec7859f46',
  statusCode: 400,
  retryable: false,
  retryDelay: 109.59137506513541
}
Template format error: The Value field of every Outputs member must evaluate to a String.

Environment

  • CLI Version :
  • Framework Version:
  • OS :
  • Language :

Other


This is 🐛 Bug Report

@nunezro2 nunezro2 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 21, 2020
@SomayaB
Copy link
Contributor

SomayaB commented Jan 21, 2020

Hi @nunezro2, thanks for submitting an issue. In order to have a better understanding of what the problem is we need a bit more information. Could you edit the original post and fill out the template as much as possible. Thanks!

@SomayaB SomayaB added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jan 21, 2020
@SomayaB SomayaB self-assigned this Jan 21, 2020
@SomayaB SomayaB added package/vpc and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Jan 30, 2020
@SomayaB SomayaB assigned rix0rrr and unassigned SomayaB Jan 30, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Feb 3, 2020

Looks like the bug report is that Fn.select() doesn't actually output a { Fn::Select } intrinsic, which I can hardly imagine.

Closing until we get a repro.

@rix0rrr rix0rrr closed this as completed Feb 3, 2020
@giovannidegani
Copy link

I can report the same issue with InterfaceVpcEndpoint

in one stack I have:

this.endpointDNS = Fn.select(0, this.endpointService.vpcEndpointDnsEntries);

Then the output of that stack is:

"Outputs": {
    "ExportsOutputFnGetAttsapgatewayvpcendpoint99C0B197DnsEntriesC7F2A387": {
      "Value": {
        "Fn::GetAtt": [
          "sapgatewayvpcendpoint99C0B197",
          "DnsEntries"
        ]
      },
      "Export": {
        "Name": "SAPGatewayProxyEndpointClient:ExportsOutputFnGetAttsapgatewayvpcendpoint99C0B197DnsEntriesC7F2A387"
      }
    }
  }

And then Fn::Split happens at the "consumption" stack

{
   "Name":"HOST",
   "Value":{
      "Fn::Join":[
         "",
         [
            {
               "Fn::Select":[
                  0,
                  {
                     "Fn::ImportValue":"SAPGatewayProxyEndpointClient:ExportsOutputFnGetAttsapgatewayvpcendpoint99C0B197DnsEntriesC7F2A387"
                  }
               ]
            },
            "}:443"
         ]
      ]
   }
},`

@timpur
Copy link

timpur commented May 20, 2020

I have experience the same issue had had to create my own way around it (not ideal :P)

@SomayaB and @rix0rrr you asked about example code, here it is (https://github.com/timpur/aws-cdk-issue-5897/blob/master/cdk.out/Stack1.template.json#L18).

Very basic stack but produces the issue. Seems the select happens in the consumer which is fine bout the generated output doesnt account for refs that are arrays of strings ....

I imagine is something to do with this line (https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/core/lib/private/refs.ts#L183)

Thanks. Hopes this helps

@SomayaB SomayaB added @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud and removed package/vpc labels May 27, 2020
@SomayaB SomayaB reopened this Jun 18, 2020
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Jun 18, 2020
@rix0rrr
Copy link
Contributor

rix0rrr commented Jun 19, 2020

Oh yes I see what's going on now. You do the select in the other stack. Overlooked it the first time around, sorry.

Not even sure if we have enough information at runtime to properly encode this, but we can see.


The solution will have to look like:

  • Whenever array tokens are exported, we should export a { Fn::Join } expression, and on import they should be imported as { Fn::Split: { Fn:: ImportValue }}.

Question is, do we have enough information to detect the token type when this link is being established?

@rix0rrr rix0rrr added @aws-cdk/core Related to core CDK functionality and removed @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud labels Jun 19, 2020
@rix0rrr rix0rrr changed the title Exporting values of array types instead of strings Automatic token exports can not be arrays Jun 19, 2020
@rix0rrr rix0rrr added the p2 label Jun 19, 2020
@NetaNir NetaNir added the effort/medium Medium work item – several days of effort label Aug 10, 2020
@diegofd
Copy link

diegofd commented Oct 4, 2020

I've just found this same error when passing a VPC object as parameter between two stacks: if an InterfaceEndpoint is defined in the VPC one output (with DnsEntries) is created and the failure appears.

@alfianabdi
Copy link

alfianabdi commented Feb 16, 2021

I also have found the same error. In my case I am passing ICluster interface between stack, the CDK magic then create the following output:

"ExportsOutputRefeksMasterSubnetIdsE751B2B7": { "Value": { "Ref": "eksMasterSubnetIds" }, "Export": { "Name": "SharedEksStack:ExportsOutputRefeksMasterSubnetIdsE751B2B7" } },

eksMasterSubnetIds is a CfnParameter which type is CommaDelimitedList.

@ritam777
Copy link

ritam777 commented May 5, 2021

I've just found this same error when passing a VPC object as parameter between two stacks: if an InterfaceEndpoint is defined in the VPC one output (with DnsEntries) is created and the failure appears.

@diegofd Were you able to fix this, I faced the exact same issue.

@timpur
Copy link

timpur commented May 6, 2021

I worked around this by manually exporting it my self correctly and importing it .... sad

@ritam777
Copy link

ritam777 commented May 7, 2021

@rix0rrr rix0rrr removed their assignment Jun 3, 2021
@soynog
Copy link

soynog commented Jun 30, 2021

I worked around this by manually exporting it my self correctly and importing it .... sad

@timpur Any chance you (or someone) could share a code snippet that demonstrates what you mean by this? Still struggling with this issue...

@eugensclifos
Copy link

@soynog you can try something like this, manual export and import with a little bit of magic.
For export:
new CfnOutput(this, 'ArrayOfStringsExport', { value: Fn.join(',', arrayOfStrings), exportName: 'exportName' });
For import:
Fn.select(0, Fn.split(',', Fn.importValue('exportName')))

@soynog
Copy link

soynog commented Jul 1, 2021

This worked for me! Thanks so much for the help @eugensclifos

@github-actions
Copy link

github-actions bot commented Jul 1, 2022

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

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jul 1, 2022
@arkon
Copy link
Contributor

arkon commented Jul 1, 2022

Would be ideal if the manual workaround wasn't needed.

@github-actions github-actions bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jul 1, 2022
@comcalvi
Copy link
Contributor

Fixed by #22873.

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. effort/medium Medium work item – several days of effort p2
Projects
None yet
Development

No branches or pull requests