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

(custom-resources): broken usage of list tokens in parameters #14088

Closed
MrArnoldPalmer opened this issue Apr 9, 2021 · 5 comments · Fixed by #14138
Closed

(custom-resources): broken usage of list tokens in parameters #14088

MrArnoldPalmer opened this issue Apr 9, 2021 · 5 comments · Fixed by #14138
Assignees
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@MrArnoldPalmer
Copy link
Contributor

Referencing a token that is a list of strings within a custom resource parameters object results in a reference to an undefined parameter.

Reproduction Steps

Reproduction App

import * as cdk from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cr from '@aws-cdk/custom-resources';

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

    const vpc = new ec2.Vpc(this, 'MyVpc');

    const vpce = new ec2.InterfaceVpcEndpoint(this, 'MyVpcEndpoint', {
      vpc,
      service: {
        name: 'com.amazonaws.us-east-1.execute-api',
        port: 443
      }
    });

    const policy = cr.AwsCustomResourcePolicy.fromSdkCalls({
      resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
    });

    new cr.AwsCustomResource(this, 'GetEdnpointIp', {
      policy,
      onUpdate: {
        service: 'EC2',
        action: 'DescribeNetworkInterfaces',
        outputPath: 'NetworkInterfaces.${index}.PrivateIpAddress',
        parameters: {
          // NetworkInterfaceIds: vpce.vpcEndpointNetworkInterfaceIds,
          NetworkInterfaceIds: [cdk.Token.asList(cdk.Stack.of(this).toJsonString(cdk.Fn.join('","', vpce.vpcEndpointNetworkInterfaceIds)))]
        },
        physicalResourceId: cr.PhysicalResourceId.of('resourceid'),
      }
    });
  }
}

What did you expect to happen?

Deploys the app to cloudformation with the CR having access to the vpce network interface IDs as json.

What actually happened?

cdk deploy results in

Template error: instance of Fn::GetAtt references undefined resource CdkJsonStringify3

Environment

  • CDK CLI Version : 1.97.0
  • Framework Version: 1.97.0
  • Node.js Version: 14.15.4
  • OS : MacOS
  • Language (Version): all

Other

Related to some recent changes:
#13465
#13544


This is 🐛 Bug Report

@MrArnoldPalmer MrArnoldPalmer added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. @aws-cdk/custom-resources Related to AWS CDK Custom Resources labels Apr 9, 2021
@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 12, 2021

Not sure what to make of the following:

          // NetworkInterfaceIds: vpce.vpcEndpointNetworkInterfaceIds,
          NetworkInterfaceIds: [cdk.Token.asList(cdk.Stack.of(this).toJsonString(cdk.Fn.join('","', vpce.vpcEndpointNetworkInterfaceIds)))]

Is the first one broken, the 2nd one a workaround?

[Token.asList(...)]

Is confusing me a little because it would end up as [[ x, y, z]] which seems not intended. At the same time, that shouldn't cause the error you're seeing.

@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 12, 2021

❤️ on the repro though. Feature haz test but I can confirm this example fails. Hey-ho, a-digging we will go

@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 12, 2021

  CdkJsonStringify1:
    Type: Custom::AWSCDKCfnJsonStringify
    Properties:
            - Fn::GetAtt:
                - CdkJsonStringify3
                - Value

😳

Must be because of separate prepare/synth cycles.

🤬

@MrArnoldPalmer
Copy link
Contributor Author

Oooh sorry, yeah the second one was an attempt at a workaround but both failed.

rix0rrr added a commit that referenced this issue Apr 13, 2021
For reasons explained in the previous PR, list tokens need to be run
through a custom resource. This custom resource gets added during token
resolution, but because that is run multiple times the side effect
of adding the custom resource gets executed multiple times.

Add a cache to make sure the second execution returns the first answer
as the first one.

Not a fantastic solution, but given the constraints of Lazies, I'm not
sure we can do any better.

Fixes #14088.
@mergify mergify bot closed this as completed in #14138 Apr 15, 2021
mergify bot pushed a commit that referenced this issue Apr 15, 2021
…14138)

For reasons explained in the previous PR, list tokens need to be run
through a custom resource. This custom resource gets added during token
resolution, but because that is run multiple times the side effect
of adding the custom resource gets executed multiple times.

Add a cache to make sure the second execution returns the first answer
as the first one.

Not a fantastic solution, but given the constraints of Lazies, I'm not
sure we can do any better.

Fixes #14088.


----

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

hollanddd pushed a commit to hollanddd/aws-cdk that referenced this issue Aug 26, 2021
…ws#14138)

For reasons explained in the previous PR, list tokens need to be run
through a custom resource. This custom resource gets added during token
resolution, but because that is run multiple times the side effect
of adding the custom resource gets executed multiple times.

Add a cache to make sure the second execution returns the first answer
as the first one.

Not a fantastic solution, but given the constraints of Lazies, I'm not
sure we can do any better.

Fixes aws#14088.


----

*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
@aws-cdk/custom-resources Related to AWS CDK Custom Resources bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants