aws-cdk: :exclamation: NOTICE (custom-resources): attribute error - vendor response doesn't contain `endpointAddress`

Please add your +1 👍 to let us know you have encountered this


Status: In progress

Describe the bug

If I upgrade cdk & cdk-lib to 2.138.0 from 2.137.0, the following error occurs at deployment. If I rollback, the error goes away.

CustomResource attribute error: Vendor response doesn't contain endpointAddress attribute in object ...|...IoTEndpoint

This was previously working for quite some time.

The specific resource is an AwsCustomResource related to IoT. (I could not find a way to get the endpoint using aws-cdk-lib/aws-iot, so had to use a custom resource)

Code repro below.

Expected Behavior

Deployment succeeds

Current Behavior

Deployment fails with the following error:

8:34:21 AM | UPDATE_FAILED        | AWS::SSM::Parameter             | fooservice/Stage2...IotEndpointAddress
CustomResource attribute error: Vendor response doesn't contain endpointAddress attribute in object
arn:aws:cloudformation:eu-central-1:<account>:stack/<...>|...IoTEndpoint...

Reproduction Steps

    import * as cus from 'aws-cdk-lib/custom-resources'

    // https://stackoverflow.com/a/77092236
    const getIoTEndpoint = new cus.AwsCustomResource(this, 'IoTEndpoint', {
      onCreate: {
        service: 'Iot',
        action: 'describeEndpoint',
        // I am guessing the failure is on the following line (and/or below)
        physicalResourceId: cus.PhysicalResourceId.fromResponse('endpointAddress'),
        parameters: {
          endpointType: 'iot:Data-ATS'
        }
      },
      policy: cus.AwsCustomResourcePolicy.fromSdkCalls({ resources: cus.AwsCustomResourcePolicy.ANY_RESOURCE })
    })

    // I am guessing the failure is on the following line (and/or above)
    const IOT_ENDPOINT = getIoTEndpoint.getResponseField('endpointAddress') // eg, abc...xyz-ats.iot.us-west-2.amazonaws.com

Possible Solution

Rollback cdk-lib to 2.137.0

Additional Information/Context

No response

CDK CLI Version

2.119.0 (build 0392e71)

Framework Version

2.138.0

Node.js Version

v20.7.0

OS

MacOS

Language

TypeScript

Language Version

5.4.5

Other information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 19 (14 by maintainers)

Commits related to this issue

Most upvoted comments

In our case, with the help of AWS support, we were able to identify the problem, which was a missing onUpdate handler, which is required when performing a CDK version upgrade due to the added property.

We are now using the same handler for onCreate and onUpdate which returns the group name properly.

// AWS Custom Resource to dynamically fetch GroupId based on group name
export const getGroupId = (scope: Construct, identityStoreId: string, group: string, logGroup: logs.LogGroup) => new cr.AwsCustomResource(scope, `getGroupId-${group}`, {
  onCreate: getGroupIdSdkCall(identityStoreId, group),
  onUpdate: getGroupIdSdkCall(identityStoreId, group),
  policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
    resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
  }),
  logGroup,
});

I’m not sure if this is a “breaking change” or not, but I would suggest highlighting this properly in the changelog that the CDK version upgrade will cause an update to all Custom Resources.

This caused a bit of a fire drill for me today, too. I’m using a Custom Resource to work around the lack of native CloudFormation support of AWS::IdentityStore::User.

Previously, I had this code:

const user = new AwsCustomResource(this, `${emailAddress}User`, {
  resourceType: 'Custom::IdentityStoreUser',
  onCreate: {
    service: '@aws-sdk/client-identitystore',
    action: 'CreateUserCommand',
    parameters: {
      IdentityStoreId: identityStoreId,
      UserName: emailAddress,
      DisplayName: userInfo.name,
      Emails: [
        {
          Value: emailAddress,
          Type: 'Work',
          Primary: true,
        },
      ],
      Name: {
        GivenName: firstName,
        FamilyName: lastName,
      },
    },
    physicalResourceId: PhysicalResourceId.fromResponse('UserId'),
  },
  onDelete: {
    service: '@aws-sdk/client-identitystore',
    action: 'DeleteUserCommand',
    parameters: {
      IdentityStoreId: identityStoreId,
      UserId: new PhysicalResourceIdReference(),
    },
  },
  policy: AwsCustomResourcePolicy.fromStatements([
    new PolicyStatement({
      actions: ['identitystore:CreateUser', 'identityStore:UpdateUser', 'identitystore:DeleteUser'],
      resources: [identityStoreArn, 'arn:aws:identitystore:::user/*'],
    }),
  ]),
});

// Add the user to the specified groups
userInfo.groupMembership.forEach((groupName) => {
  new CfnGroupMembership(this, `${emailAddress}${groupName}Membership`, {
    identityStoreId,
    groupId: groups[groupName].attrGroupId,
    memberId: { userId: user.getResponseField('UserId') },
  });
});

When I upgraded from 2.136.0 => 2.140.0, I started getting errors that looked like this:

Vendor response doesn't contain UserId attribute in object

The fix for me was changing the getResponseField code to use the Physical ID I’m setting on the user object:

// Add the user to the specified groups
userInfo.groupMembership.forEach((groupName) => {
  new CfnGroupMembership(this, `${emailAddress}${groupName}Membership`, {
    identityStoreId,
    groupId: groups[groupName].attrGroupId,
    memberId: { userId: (user.node.defaultChild as CustomResource).ref },  // <-- this is the change
  });
});

The documentation mentions that I shouldn’t use getResponseField in my case (without an update call), but I missed it the first time:

AwsCustomResource.getResponseField() and .getResponseFieldReference() will not work if the Create and Update APIs don’t consistently return the same fields.

I also added an onUpdate that calls UpdateUserCommand for good measure.

@markusl Thanks for the follow-up and I agree, this feels like a documentation miss on our end. From the perspective of the custom resource it saw an update and didn’t make an API call which is how it was configured. However, obviously you now don’t have a groupId since your custom resource was configured to only make the API call on a create event. We’ll work on improving the documentation for this.

@pahud I can also confirm that there is a breaking change in AwsCustomResource after 2.137.0.

export const getGroupId = (scope: Construct, identityStoreId: string, group: string, logGroup: logs.LogGroup) =>
  new cr.AwsCustomResource(scope, `getGroupId-${group}`, {
    onCreate: {
      service: 'IdentityStore',
      action: 'getGroupId',
      parameters: {
        IdentityStoreId: identityStoreId,
        AlternateIdentifier: {
          UniqueAttribute: {
            AttributePath: 'DisplayName',
            AttributeValue: group,
          },
        },
      },
      physicalResourceId: cr.PhysicalResourceId.fromResponse('GroupId'),
    },
    policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
      resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
    }),
    logGroup,
  });

The error message is CustomResource attribute error: Vendor response doesn't contain GroupId attribute in object arn:aws:cloudformation:us-east-8:999999999999:stack/stack-name. The GroupId does exist and is returned from the API when doing the API call.

Can you please have a look at this since it is quite critical and would block us from deploying AWS SSO Assignments?

Regards, Markus