Skip to content

Commit

Permalink
migrate & cleanup test handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain committed Sep 8, 2023
1 parent 7d8dca2 commit 4390149
Show file tree
Hide file tree
Showing 36 changed files with 571 additions and 2,548 deletions.
3 changes: 3 additions & 0 deletions packages/@aws-cdk-testing/framework-integ/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"@aws-cdk/cdk-build-tools": "0.0.0",
"@aws-cdk/integ-runner": "^0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@aws-sdk/client-acm": "3.408.0",
"@aws-sdk/client-rds": "3.408.0",
"@aws-sdk/client-s3": "3.408.0",
"delay": "5.0.0"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Construct } from 'constructs';
import * as rds from 'aws-cdk-lib/aws-rds';
import { ClusterInstance } from 'aws-cdk-lib/aws-rds';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import { STANDARD_NODEJS_RUNTIME } from '../../config';

class TestStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
Expand Down Expand Up @@ -85,7 +86,7 @@ class Snapshoter extends Construct {
const code = lambda.Code.fromAsset(path.join(__dirname, 'snapshot-handler'));
const onEventHandler = new lambda.Function(this, 'OnEventHandler', {
code,
runtime: lambda.Runtime.NODEJS_16_X,
runtime: STANDARD_NODEJS_RUNTIME,
handler: 'index.onEventHandler',
});
onEventHandler.addToRolePolicy(new iam.PolicyStatement({
Expand All @@ -95,7 +96,7 @@ class Snapshoter extends Construct {

const isCompleteHandler = new lambda.Function(this, 'IsCompleteHandler', {
code,
runtime: lambda.Runtime.NODEJS_16_X,
runtime: STANDARD_NODEJS_RUNTIME,
handler: 'index.isCompleteHandler',
});
isCompleteHandler.addToRolePolicy(new iam.PolicyStatement({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
/// <reference path="../../../../../../../node_modules/aws-cdk-lib/custom-resources/lib/provider-framework/types.d.ts" />
import { RDS } from 'aws-sdk'; // eslint-disable-line import/no-extraneous-dependencies
import { RDS } from '@aws-sdk/client-rds'; // eslint-disable-line import/no-extraneous-dependencies

export async function onEventHandler(event: AWSCDKAsyncCustomResource.OnEventRequest): Promise<AWSCDKAsyncCustomResource.OnEventResponse> {
console.log('Event: %j', event);
Expand All @@ -13,7 +13,7 @@ export async function onEventHandler(event: AWSCDKAsyncCustomResource.OnEventReq
const data = await rds.createDBClusterSnapshot({
DBClusterIdentifier: event.ResourceProperties.DBClusterIdentifier,
DBClusterSnapshotIdentifier: event.ResourceProperties.DBClusterSnapshotIdentifier,
}).promise();
});
return {
PhysicalResourceId: physicalResourceId,
Data: {
Expand All @@ -25,7 +25,7 @@ export async function onEventHandler(event: AWSCDKAsyncCustomResource.OnEventReq
if (event.RequestType === 'Delete') {
await rds.deleteDBClusterSnapshot({
DBClusterSnapshotIdentifier: event.ResourceProperties.DBClusterSnapshotIdentifier,
}).promise();
});
}

return {
Expand All @@ -52,7 +52,7 @@ async function tryGetClusterSnapshotStatus(identifier: string): Promise<string |
const rds = new RDS();
const data = await rds.describeDBClusterSnapshots({
DBClusterSnapshotIdentifier: identifier,
}).promise();
});
return data.DBClusterSnapshots?.[0].Status;
} catch (err: any) {
if (err.code === 'DBClusterSnapshotNotFoundFault') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as path from 'path';
import { App, CustomResource, CustomResourceProvider, CustomResourceProviderRuntime, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib';
import { App, CustomResource, CustomResourceProvider, RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import { Construct } from 'constructs';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId } from 'aws-cdk-lib/custom-resources';
import { STANDARD_CUSTOM_RESOURCE_PROVIDER_RUNTIME } from '../../config';

const PUT_OBJECTS_RESOURCE_TYPE = 'Custom::S3PutObjects';

Expand All @@ -19,7 +20,7 @@ class TestStack extends Stack {
// Put objects in the bucket to ensure auto delete works as expected
const serviceToken = CustomResourceProvider.getOrCreate(this, PUT_OBJECTS_RESOURCE_TYPE, {
codeDirectory: path.join(__dirname, 'put-objects-handler'),
runtime: CustomResourceProviderRuntime.NODEJS_16_X,
runtime: STANDARD_CUSTOM_RESOURCE_PROVIDER_RUNTIME,
policyStatements: [{
Effect: 'Allow',
Action: 's3:PutObject',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { S3 } from 'aws-sdk';
import { S3 } from '@aws-sdk/client-s3';

const s3 = new S3();

Expand Down Expand Up @@ -27,5 +27,5 @@ async function putObjects(bucketName: string, n = 5) {
Bucket: bucketName,
Key: `Key${key}`,
Body: `Body${key}`,
}).promise()));
})));
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/// <reference path="../../../../../../../../../node_modules/aws-cdk-lib/custom-resources/lib/provider-framework/types.d.ts" />
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable no-console */
import * as AWS from 'aws-sdk';
import { S3 } from '@aws-sdk/client-s3';
import * as api from './api';

const s3 = new AWS.S3();
const s3 = new S3();

export async function onEvent(event: AWSCDKAsyncCustomResource.OnEventRequest) {
switch (event.RequestType) {
Expand Down Expand Up @@ -41,7 +42,7 @@ export async function putObject(event: AWSCDKAsyncCustomResource.OnEventRequest)
Key: objectKey,
Body: contents,
ACL: publicRead ? 'public-read' : undefined,
}).promise();
});

// NOTE: updates to the object key will be handled automatically: a new object will be put and then we return
// the new name. this will tell cloudformation that the resource has been replaced and it will issue a DELETE
Expand Down Expand Up @@ -69,5 +70,5 @@ export async function deleteObject(event: AWSCDKAsyncCustomResource.OnEventReque
await s3.deleteObject({
Bucket: bucketName,
Key: objectKey,
}).promise();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CustomResource, Stack } from 'aws-cdk-lib';
import { Construct, Node } from 'constructs';
import * as api from './s3-file-handler/api';
import * as cr from 'aws-cdk-lib/custom-resources';
import { STANDARD_NODEJS_RUNTIME } from '../../../../config';

interface S3FileProps {
/**
Expand Down Expand Up @@ -78,7 +79,7 @@ class S3FileProvider extends Construct {
this.provider = new cr.Provider(this, 's3file-provider', {
onEventHandler: new lambda.Function(this, 's3file-on-event', {
code: lambda.Code.fromAsset(path.join(__dirname, 's3-file-handler')),
runtime: lambda.Runtime.NODEJS_16_X,
runtime: STANDARD_NODEJS_RUNTIME,
handler: 'index.onEvent',
initialPolicy: [
new iam.PolicyStatement({
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-codepipeline-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ const lambdaInvokeAction = new codepipeline_actions.LambdaInvokeAction({
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
code: lambda.Code.fromInline(`
const AWS = require('aws-sdk');
const { CodePipeline } = require('@aws-sdk/client-codepipeline');
exports.handler = async function(event, context) {
const codepipeline = new AWS.CodePipeline();
Expand All @@ -1157,7 +1157,7 @@ const lambdaInvokeAction = new codepipeline_actions.LambdaInvokeAction({
outputVariables: {
MY_VAR: "some value",
},
}).promise();
});
}
`),
}),
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4390149

Please sign in to comment.