Skip to content

Commit

Permalink
fix(integ-tests): AwsApiCall Custom Resource length could be greater …
Browse files Browse the repository at this point in the history
…than 60 characters (#22119)

Limits the resource type name to 60 characters to account for CloudFormation limitations with Custom Resource Resource Types


Closes #22055


----

### All Submissions:

* [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
dontirun committed Sep 20, 2022
1 parent e860ffc commit 35b2806
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/@aws-cdk/integ-tests/lib/assertions/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CustomResource, Reference, Lazy, CfnResource, Stack, ArnFormat } from '@aws-cdk/core';
import { ArnFormat, CfnResource, CustomResource, Lazy, Reference, Stack } from '@aws-cdk/core';
import { Construct, IConstruct } from 'constructs';
import { EqualsAssertion } from './assertions';
import { ExpectedResult, ActualResult } from './common';
import { ActualResult, ExpectedResult } from './common';
import { AssertionsProvider, SDK_RESOURCE_TYPE_PREFIX } from './providers';

/**
Expand Down Expand Up @@ -113,7 +113,7 @@ export interface AwsApiCallOptions {
/**
* Options for creating an SDKQuery provider
*/
export interface AwsApiCallProps extends AwsApiCallOptions {}
export interface AwsApiCallProps extends AwsApiCallOptions { }

/**
* Construct that creates a custom resource that will perform
Expand Down Expand Up @@ -142,7 +142,7 @@ export class AwsApiCall extends Construct implements IAwsApiCall {
flattenResponse: Lazy.string({ produce: () => this.flattenResponse }),
salt: Date.now().toString(),
},
resourceType: `${SDK_RESOURCE_TYPE_PREFIX}${this.name}`,
resourceType: `${SDK_RESOURCE_TYPE_PREFIX}${this.name}`.substring(0, 60),
});

// Needed so that all the policies set up by the provider should be available before the custom resource is provisioned.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Template } from '@aws-cdk/assertions';
import { App, Stack } from '@aws-cdk/core';
import { LogType, InvocationType, ExpectedResult, ActualResult } from '../../lib/assertions';
import { ActualResult, ExpectedResult, InvocationType, LogType } from '../../lib/assertions';
import { DeployAssert } from '../../lib/assertions/private/deploy-assert';

describe('DeployAssert', () => {
Expand Down Expand Up @@ -145,5 +145,22 @@ describe('DeployAssert', () => {
template.resourceCountIs('Custom::DeployAssert@SdkCallMyServiceMyApi1', 1);
template.resourceCountIs('Custom::DeployAssert@SdkCallMyServiceMyApi2', 1);
});

test('custom resource type length is truncated when greater than 60 characters', () => {
// GIVEN
const app = new App();

// WHEN
const deplossert = new DeployAssert(app);
deplossert.awsApiCall('Pangram', 'TheQuickBrownFoxJumpsOverTheLazyDog');

// THEN
const truncatedType = 'Custom::DeployAssert@SdkCallPangramTheQuickBrownFoxJumpsOver';
expect(truncatedType.length).toEqual(60);

const template = Template.fromStack(deplossert.scope);
template.resourceCountIs('AWS::Lambda::Function', 1);
template.resourceCountIs(truncatedType, 1);
});
});
});

0 comments on commit 35b2806

Please sign in to comment.