Skip to content

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

@MrArnoldPalmer

Description

@MrArnoldPalmer

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

Metadata

Metadata

Assignees

Labels

@aws-cdk/custom-resourcesRelated to AWS CDK Custom ResourcesbugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions