Skip to content

Commit 93df62a

Browse files
authored
chore(custom-resource-handlers): lint (#33204)
The linter in the custom-resource-handlers folder was never turned on, resulting in typos, inconsistencies, and potentially bugs. This PR does not fix any potential bugs. I have tracked them in separate issues. There's more work to be done with the generated files that we are not linting right now, but this is better than nothing ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent c76f668 commit 93df62a

File tree

35 files changed

+117
-85
lines changed

35 files changed

+117
-85
lines changed

packages/@aws-cdk/custom-resource-handlers/.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const baseConfig = require('@aws-cdk/cdk-build-tools/config/eslintrc');
22
baseConfig.parserOptions.project = __dirname + '/tsconfig.dev.json';
3+
baseConfig.ignorePatterns = [
4+
...baseConfig.ignorePatterns || [],
5+
'test/custom-resources-framework/expected/**', // ignore generated files
6+
];
37
baseConfig.rules['import/no-extraneous-dependencies'] = [
48
'error',
59
{

packages/@aws-cdk/custom-resource-handlers/README.md

+22-3
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,37 @@
22

33
This package contains the following custom resource handlers:
44

5-
### Stable:
5+
## Stable
66

7-
- aws-s3/auto-delete-objects-handler
7+
- aws-certificatemanager/dns-validated-certificate-handler
8+
- aws-cloudfront/edge-function
9+
- aws-dynamodb/replica-handler
10+
- aws-ec2/restrict-default-security-group-handler
811
- aws-ecr/auto-delete-images-handler
12+
- aws-ecs/lambda-source
13+
- aws-eks/custom-resource-handler
14+
- aws-eks/kubectl-handler
915
- aws-events-targets/aws-api-handler
16+
- aws-iam/oidc-handler
17+
- aws-logs/log-retention-handler
18+
- aws-route53/cross-account-zone-delegation-handler
19+
- aws-route53/delete-existing-record-set-handler
20+
- aws-s3/auto-delete-objects-handler
21+
- aws-s3/notifications-resource-handler
22+
- aws-s3-deployment/bucket-deployment-handler
23+
- aws-ses/drop-spam-handler
24+
- aws-stepfunctions-tasks/cross-region-aws-sdk-handler
25+
- aws-stepfunctions-tasks/eval-nodejs-handler
26+
- aws-stepfunctions-tasks/role-policy-handler
1027
- aws-synthetics/auto-delete-underlying-resources-handler
1128
- custom-resources/aws-custom-resource-handler
29+
- pipelines/approve-lambda
30+
- triggers/lambda
1231

1332
These handlers are copied into `aws-cdk-lib/custom-resource-handlers` at build time
1433
and included as part of the `aws-cdk-lib` package.
1534

16-
### Experimental:
35+
## Experimental
1736

1837
- aws-amplify-alpha/asset-deployment-handler
1938
- aws-redshift-alpha/asset-deployment-handler

packages/@aws-cdk/custom-resource-handlers/lib/aws-amplify-alpha/asset-deployment-handler/common.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface IsCompleteResponse {
1919
* Additional/changes to resource attributes.
2020
*/
2121
readonly Data?: { [name: string]: any };
22-
};
22+
}
2323

2424
export abstract class ResourceHandler {
2525
protected readonly requestId: string;

packages/@aws-cdk/custom-resource-handlers/lib/aws-ecr/auto-delete-images-handler/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function autoDeleteHandler(event: AWSLambda.CloudFormationCustomRes
1818
case 'Delete':
1919
return onDelete(event.ResourceProperties?.RepositoryName);
2020
}
21-
};
21+
}
2222

2323
async function onUpdate(event: AWSLambda.CloudFormationCustomResourceEvent) {
2424
const updateEvent = event as AWSLambda.CloudFormationCustomResourceUpdateEvent;

packages/@aws-cdk/custom-resource-handlers/lib/aws-eks/cluster-resource-handler/cluster.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ export class ClusterResourceHandler extends ResourceHandler {
208208
};
209209
if (updates.updateLogging) {
210210
config.logging = this.newProps.logging;
211-
};
211+
}
212212
if (updates.updateAccess) {
213213
config.resourcesVpcConfig = {
214214
endpointPrivateAccess: this.newProps.resourcesVpcConfig?.endpointPrivateAccess,
215215
endpointPublicAccess: this.newProps.resourcesVpcConfig?.endpointPublicAccess,
216216
publicAccessCidrs: this.newProps.resourcesVpcConfig?.publicAccessCidrs,
217217
};
218-
};
218+
}
219219

220220
if (updates.updateAuthMode) {
221221
// the update path must be
@@ -259,7 +259,7 @@ export class ClusterResourceHandler extends ResourceHandler {
259259
throw e;
260260
}
261261
config.accessConfig = this.newProps.accessConfig;
262-
};
262+
}
263263

264264
if (updates.updateVpc) {
265265
config.resourcesVpcConfig = {
@@ -481,7 +481,7 @@ function getTagsToUpdate<T extends Record<string, string>>(oldTags: T, newTags:
481481

482482
function getTagsToRemove<T extends Record<string, string>>(oldTags: T, newTags: T): string[] {
483483
const missingKeys: string[] = [];
484-
//Get all tag keys to remove
484+
// Get all tag keys to remove
485485
for (const key in oldTags) {
486486
if (oldTags.hasOwnProperty(key) && !newTags.hasOwnProperty(key)) {
487487
missingKeys.push(key);
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const CLUSTER_RESOURCE_TYPE = 'Custom::AWSCDK-EKS-Cluster';
2-
export const FARGATE_PROFILE_RESOURCE_TYPE = 'Custom::AWSCDK-EKS-FargateProfile';
2+
export const FARGATE_PROFILE_RESOURCE_TYPE = 'Custom::AWSCDK-EKS-FargateProfile';

packages/@aws-cdk/custom-resource-handlers/lib/aws-redshift-alpha/cluster-parameter-change-reboot-handler/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function rebootClusterIfRequired(clusterId: string, parameterGroupName: st
2222
await redshift.rebootCluster({ ClusterIdentifier: clusterId });
2323
} catch (err: any) {
2424
if (err.name === 'InvalidClusterStateFault') {
25-
return await executeActionForStatus(status, 30000);
25+
return executeActionForStatus(status, 30000);
2626
} else {
2727
throw err;
2828
}

packages/@aws-cdk/custom-resource-handlers/lib/aws-route53/cross-account-zone-delegation-handler/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ export type CrossAccountZoneDelegationEvent = AWSLambda.CloudFormationCustomReso
99
}
1010

1111
interface ResourceProperties {
12-
AssumeRoleArn: string,
13-
ParentZoneName?: string,
14-
ParentZoneId?: string,
15-
DelegatedZoneName: string,
16-
DelegatedZoneNameServers: string[],
17-
TTL: number,
18-
AssumeRoleRegion?: string,
12+
AssumeRoleArn: string;
13+
ParentZoneName?: string;
14+
ParentZoneId?: string;
15+
DelegatedZoneName: string;
16+
DelegatedZoneNameServers: string[];
17+
TTL: number;
18+
AssumeRoleRegion?: string;
1919
}
2020

2121
export async function handler(event: CrossAccountZoneDelegationEvent) {
@@ -129,4 +129,4 @@ function route53Region(region: string) {
129129

130130
// Default for commercial partition
131131
return 'us-east-1';
132-
}
132+
}

packages/@aws-cdk/custom-resource-handlers/lib/aws-s3/auto-delete-objects-handler/index.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function autoDeleteHandler(event: AWSLambda.CloudFormationCustomRes
2020
case 'Delete':
2121
return onDelete(event.ResourceProperties?.BucketName);
2222
}
23-
};
23+
}
2424

2525
async function onUpdate(event: AWSLambda.CloudFormationCustomResourceEvent) {
2626
const updateEvent = event as AWSLambda.CloudFormationCustomResourceUpdateEvent;
@@ -30,8 +30,8 @@ async function onUpdate(event: AWSLambda.CloudFormationCustomResourceEvent) {
3030
/* If the name of the bucket has changed, CloudFormation will try to delete the bucket
3131
and create a new one with the new name. Returning a PhysicalResourceId that differs
3232
from the event's PhysicalResourceId will trigger a `Delete` event for the custom
33-
resource, note that this is default CFN behaviour. The `Delete` event will trigger
34-
`onDelete` function which will empty the content of the bucket and then proceed to
33+
resource, note that this is default CFN behaviour. The `Delete` event will trigger
34+
`onDelete` function which will empty the content of the bucket and then proceed to
3535
delete the bucket. */
3636
return { PhysicalResourceId: newBucketName };
3737
}
@@ -51,6 +51,8 @@ async function denyWrites(bucketName: string) {
5151
Principal: '*',
5252
Effect: 'Deny',
5353
Action: ['s3:PutObject'],
54+
// TODO: this is probably an error of some sort
55+
// eslint-disable-next-line @cdklabs/no-literal-partition
5456
Resource: [`arn:aws:s3:::${bucketName}/*`],
5557
},
5658
);
@@ -85,7 +87,7 @@ async function emptyBucket(bucketName: string) {
8587

8688
const records = contents.map((record) => ({ Key: record.Key, VersionId: record.VersionId }));
8789
await s3.deleteObjects({ Bucket: bucketName, Delete: { Objects: records } });
88-
} while (listedObjects?.IsTruncated)
90+
} while (listedObjects?.IsTruncated);
8991
}
9092

9193
async function onDelete(bucketName?: string) {

packages/@aws-cdk/custom-resource-handlers/lib/aws-synthetics/auto-delete-underlying-resources-handler/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function autoDeleteHandler(event: AWSLambda.CloudFormationCustomRes
2121
case 'Delete':
2222
return onDelete(event.ResourceProperties?.CanaryName);
2323
}
24-
};
24+
}
2525

2626
async function onUpdate(event: AWSLambda.CloudFormationCustomResourceEvent) {
2727
const updateEvent = event as AWSLambda.CloudFormationCustomResourceUpdateEvent;

packages/@aws-cdk/custom-resource-handlers/lib/core/cross-region-ssm-reader-handler/index.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
/*eslint-disable no-console*/
1+
/* eslint-disable no-console*/
22
/* eslint-disable import/no-extraneous-dependencies */
33
import { SSM } from '@aws-sdk/client-ssm';
4-
4+
import { ExportReaderCRProps, CrossRegionExports } from '../types';
55
// Must use a require() otherwise esbuild complains
66
// eslint-disable-next-line @typescript-eslint/no-require-imports
77
const pLimit: typeof import('p-limit') = require('p-limit');
8-
import { ExportReaderCRProps, CrossRegionExports } from '../types';
98

109
export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent) {
1110
const props: ExportReaderCRProps = event.ResourceProperties.ReaderProps;
@@ -44,7 +43,7 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
4443
return {
4544
Data: imports,
4645
};
47-
};
46+
}
4847

4948
/**
5049
* Add tag to parameters for existing exports

packages/@aws-cdk/custom-resource-handlers/lib/core/cross-region-ssm-writer-handler/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*eslint-disable no-console*/
1+
/* eslint-disable no-console*/
22
/* eslint-disable import/no-extraneous-dependencies */
33
import { SSM } from '@aws-sdk/client-ssm';
44
import { CrossRegionExports, ExportWriterCRProps } from '../types';
@@ -53,12 +53,14 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent
5353
console.error('Error processing event: ', e);
5454
throw e;
5555
}
56-
};
56+
}
5757

5858
/**
5959
* Create parameters for existing exports
6060
*/
6161
async function putParameters(ssm: SSM, parameters: CrossRegionExports): Promise<void> {
62+
// This linter exemption could be wrong. It is added into enable linting after it was turned off for some time
63+
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
6264
await Promise.all(Array.from(Object.entries(parameters), ([name, value]) => {
6365
return ssm.putParameter({
6466
Name: name,
@@ -94,6 +96,8 @@ async function deleteParameters(ssm: SSM, names: string[]) {
9496
*/
9597
async function throwIfAnyInUse(ssm: SSM, parameters: CrossRegionExports): Promise<void> {
9698
const tagResults: Map<string, Set<string>> = new Map();
99+
// This linter exemption could be wrong. It is added into enable linting after it was turned off for some time
100+
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism
97101
await Promise.all(Object.keys(parameters).map(async (name: string) => {
98102
const result = await isInUse(ssm, name);
99103
if (result.size > 0) {

packages/@aws-cdk/custom-resource-handlers/lib/triggers/lambda/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Lambda, InvocationResponse, InvocationType } from '@aws-sdk/client-lamb
55
import { NodeHttpHandler } from '@smithy/node-http-handler';
66

77
export type DecodedInvocationResponse = Omit<InvocationResponse, 'Payload'> & {
8-
Payload?: string
8+
Payload?: string;
99
}
1010

1111
export type InvokeFunction = (functionName: string, invocationType: InvocationType, timeout: number) => Promise<DecodedInvocationResponse>;

packages/@aws-cdk/custom-resource-handlers/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"version": "0.0.0",
66
"scripts": {
7-
"build": "tsc -b && node scripts/generate.js",
7+
"build": "tsc -b && node scripts/generate.js && cdk-lint",
88
"integ": "integ-runner --language javascript",
99
"lint": "cdk-lint",
1010
"package": "cdk-package",
@@ -48,7 +48,7 @@
4848
"@types/jest": "^29.5.14",
4949
"aws-sdk-client-mock": "4.1.0",
5050
"aws-sdk-client-mock-jest": "4.1.0",
51-
"@cdklabs/typewriter": "^0.0.3",
51+
"@cdklabs/typewriter": "^0.0.5",
5252
"jest": "^29.7.0",
5353
"sinon": "^9.2.4",
5454
"nock": "^13.5.5",

packages/@aws-cdk/custom-resource-handlers/test/aws-amplify-alpha/asset-deployment-handler.test.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('handler', () => {
9393
branchName: 'branchNameValue',
9494
maxResults: 1,
9595
});
96-
expect(listJobsRequest).toBeCalled();
96+
expect(listJobsRequest).toHaveBeenCalled();
9797
expect(mockGetSignedUrlResponse).toHaveBeenCalledWith(mockS3, {
9898
Bucket: 's3BucketNameValue',
9999
Key: 's3ObjectKeyValue',
@@ -103,7 +103,7 @@ describe('handler', () => {
103103
branchName: 'branchNameValue',
104104
sourceUrl: 'signedUrlValue',
105105
});
106-
expect(startDeploymentRequest).toBeCalled();
106+
expect(startDeploymentRequest).toHaveBeenCalled();
107107
});
108108

109109
it('onEvent CREATE pending job', async () => {
@@ -137,7 +137,7 @@ describe('handler', () => {
137137
branchName: 'branchNameValue',
138138
maxResults: 1,
139139
});
140-
expect(listJobsRequest).toBeCalled();
140+
expect(listJobsRequest).toHaveBeenCalled();
141141
expect(mockGetSignedUrlResponse).not.toHaveBeenCalled();
142142
expect(startDeploymentRequest).not.toHaveBeenCalled();
143143
expect(startDeploymentRequest).not.toHaveBeenCalled();
@@ -184,7 +184,7 @@ describe('handler', () => {
184184
branchName: 'branchNameValue',
185185
jobId: 'amplifyJobIdValue',
186186
});
187-
expect(getJobRequest).toBeCalled();
187+
expect(getJobRequest).toHaveBeenCalled();
188188
});
189189

190190
it('isComplete CREATE pending', async () => {
@@ -224,7 +224,7 @@ describe('handler', () => {
224224
branchName: 'branchNameValue',
225225
jobId: 'amplifyJobIdValue',
226226
});
227-
expect(getJobRequest).toBeCalled();
227+
expect(getJobRequest).toHaveBeenCalled();
228228
});
229229

230230
it('isComplete CREATE failed', async () => {
@@ -259,7 +259,7 @@ describe('handler', () => {
259259
branchName: 'branchNameValue',
260260
jobId: 'amplifyJobIdValue',
261261
});
262-
expect(getJobRequest).toBeCalled();
262+
expect(getJobRequest).toHaveBeenCalled();
263263
});
264264

265265
it('isComplete CREATE cancelled', async () => {
@@ -295,7 +295,7 @@ describe('handler', () => {
295295
branchName: 'branchNameValue',
296296
jobId: 'amplifyJobIdValue',
297297
});
298-
expect(getJobRequest).toBeCalled();
298+
expect(getJobRequest).toHaveBeenCalled();
299299
});
300300

301301
it('isComplete CREATE no JobId', async () => {
@@ -375,7 +375,7 @@ describe('handler', () => {
375375
branchName: 'branchNameValue',
376376
maxResults: 1,
377377
});
378-
expect(listJobsRequest).toBeCalled();
378+
expect(listJobsRequest).toHaveBeenCalled();
379379
expect(mockGetSignedUrlResponse).toHaveBeenCalledWith(mockS3, {
380380
Bucket: 's3BucketNameValue',
381381
Key: 's3ObjectKeyValue',
@@ -385,7 +385,7 @@ describe('handler', () => {
385385
branchName: 'branchNameValue',
386386
sourceUrl: 'signedUrlValue',
387387
});
388-
expect(startDeploymentRequest).toBeCalled();
388+
expect(startDeploymentRequest).toHaveBeenCalled();
389389
});
390390

391391
it('onEvent UPDATE pending job', async () => {
@@ -422,7 +422,7 @@ describe('handler', () => {
422422
branchName: 'branchNameValue',
423423
maxResults: 1,
424424
});
425-
expect(listJobsRequest).toBeCalled();
425+
expect(listJobsRequest).toHaveBeenCalled();
426426
expect(mockGetSignedUrlResponse).not.toHaveBeenCalled();
427427
expect(startDeploymentRequest).not.toHaveBeenCalled();
428428
expect(startDeploymentRequest).not.toHaveBeenCalled();
@@ -471,7 +471,7 @@ describe('handler', () => {
471471
branchName: 'branchNameValue',
472472
jobId: 'amplifyJobIdValue',
473473
});
474-
expect(getJobRequest).toBeCalled();
474+
expect(getJobRequest).toHaveBeenCalled();
475475
});
476476

477477
it('isComplete UPDATE pending', async () => {
@@ -513,7 +513,7 @@ describe('handler', () => {
513513
branchName: 'branchNameValue',
514514
jobId: 'amplifyJobIdValue',
515515
});
516-
expect(getJobRequest).toBeCalled();
516+
expect(getJobRequest).toHaveBeenCalled();
517517
});
518518

519519
it('isComplete UPDATE failed', async () => {
@@ -550,7 +550,7 @@ describe('handler', () => {
550550
branchName: 'branchNameValue',
551551
jobId: 'amplifyJobIdValue',
552552
});
553-
expect(getJobRequest).toBeCalled();
553+
expect(getJobRequest).toHaveBeenCalled();
554554
});
555555

556556
it('isComplete UPDATE cancelled', async () => {
@@ -588,7 +588,7 @@ describe('handler', () => {
588588
branchName: 'branchNameValue',
589589
jobId: 'amplifyJobIdValue',
590590
});
591-
expect(getJobRequest).toBeCalled();
591+
expect(getJobRequest).toHaveBeenCalled();
592592
});
593593

594594
it('isComplete UPDATE no JobId', async () => {

0 commit comments

Comments
 (0)