Skip to content

Commit

Permalink
fix: code discrepancy relative to original repo (#39)
Browse files Browse the repository at this point in the history
Copied from commit
aws/aws-cdk@411dc5a,
the one before the code removal
[PR](aws/aws-cdk#33474).

Also remove some leftover `*.js` and `*.d.ts` files in the `bin`
directory.
  • Loading branch information
iliapolo authored Feb 19, 2025
1 parent 488d7dd commit 076dcdd
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 412 deletions.
1 change: 0 additions & 1 deletion packages/@aws-cdk-testing/cli-integ/bin/query-github.d.ts

This file was deleted.

54 changes: 0 additions & 54 deletions packages/@aws-cdk-testing/cli-integ/bin/query-github.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/@aws-cdk-testing/cli-integ/bin/run-suite.d.ts

This file was deleted.

131 changes: 0 additions & 131 deletions packages/@aws-cdk-testing/cli-integ/bin/run-suite.js

This file was deleted.

This file was deleted.

217 changes: 0 additions & 217 deletions packages/@aws-cdk-testing/cli-integ/bin/stage-distribution.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/@aws-cdk-testing/cli-integ/bin/test-root.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/@aws-cdk-testing/cli-integ/bin/test-root.js

This file was deleted.

34 changes: 34 additions & 0 deletions packages/@aws-cdk-testing/cli-integ/resources/cdk-apps/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (process.env.PACKAGE_LAYOUT_VERSION === '1') {
var sns = require('@aws-cdk/aws-sns');
var sqs = require('@aws-cdk/aws-sqs');
var lambda = require('@aws-cdk/aws-lambda');
var node_lambda = require('@aws-cdk/aws-lambda-nodejs');
var sso = require('@aws-cdk/aws-sso');
var docker = require('@aws-cdk/aws-ecr-assets');
var appsync = require('@aws-cdk/aws-appsync');
Expand All @@ -28,6 +29,7 @@ if (process.env.PACKAGE_LAYOUT_VERSION === '1') {
aws_sns: sns,
aws_sqs: sqs,
aws_lambda: lambda,
aws_lambda_nodejs: node_lambda,
aws_ecr_assets: docker,
aws_appsync: appsync,
Stack
Expand Down Expand Up @@ -264,6 +266,20 @@ class ImportableStack extends cdk.Stack {
});
}

if (process.env.INCLUDE_SINGLE_BUCKET === '1') {
const bucket = new s3.Bucket(this, 'test-bucket', {
removalPolicy: (process.env.RETAIN_SINGLE_BUCKET === '1') ? cdk.RemovalPolicy.RETAIN : cdk.RemovalPolicy.DESTROY,
});

new cdk.CfnOutput(this, 'BucketLogicalId', {
value: bucket.node.defaultChild.logicalId,
});

new cdk.CfnOutput(this, 'BucketName', {
value: bucket.bucketName,
});
}

if (process.env.LARGE_TEMPLATE === '1') {
for (let i = 1; i <= 70; i++) {
new sqs.Queue(this, `cdk-import-queue-test${i}`, {
Expand All @@ -272,6 +288,24 @@ class ImportableStack extends cdk.Stack {
});
}
}

if (process.env.INCLUDE_NODEJS_FUNCTION_LAMBDA === '1') {
new node_lambda.NodejsFunction(
this,
'cdk-import-nodejs-lambda-test',
{
bundling: {
minify: true,
sourceMap: false,
sourcesContent: false,
target: 'ES2020',
forceDockerBundling: true,
},
runtime: lambda.Runtime.NODEJS_18_X,
entry: path.join(__dirname, 'lambda/index.js')
}
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This test is failing on what seems to be an upstream or dependency issue.
Skipping it because it prevents us from a release a patch.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sam can locally test the synthesized cdk application
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,73 @@ integTest(
}),
);

/**
* Create an S3 bucket, orphan that bucket, then import the bucket, with a NodeJSFunction lambda also in the stack.
*
* Validates fix for https://github.com/aws/aws-cdk/issues/31999 (import fails)
*/
integTest(
'test resource import with construct that requires bundling',
withDefaultFixture(async (fixture) => {
// GIVEN
const outputsFile = path.join(fixture.integTestDir, 'outputs', 'outputs.json');
await fs.mkdir(path.dirname(outputsFile), { recursive: true });

// First, create a stack that includes a NodeJSFunction lambda and one bucket that will be removed from the stack but NOT deleted from AWS.
await fixture.cdkDeploy('importable-stack', {
modEnv: { INCLUDE_NODEJS_FUNCTION_LAMBDA: '1', INCLUDE_SINGLE_BUCKET: '1', RETAIN_SINGLE_BUCKET: '1' },
options: ['--outputs-file', outputsFile],
});

try {
// Second, now the bucket we will remove is in the stack and has a logicalId. We can now make the resource mapping file.
// This resource mapping file will be used to tell the import operation what bucket to bring into the stack.
const fullStackName = fixture.fullStackName('importable-stack');
const outputs = JSON.parse((await fs.readFile(outputsFile, { encoding: 'utf-8' })).toString());
const bucketLogicalId = outputs[fullStackName].BucketLogicalId;
const bucketName = outputs[fullStackName].BucketName;
const bucketResourceMap = {
[bucketLogicalId]: {
BucketName: bucketName,
},
};
const mappingFile = path.join(fixture.integTestDir, 'outputs', 'mapping.json');
await fs.writeFile(mappingFile, JSON.stringify(bucketResourceMap), { encoding: 'utf-8' });

// Third, remove the bucket from the stack, but don't delete the bucket from AWS.
await fixture.cdkDeploy('importable-stack', {
modEnv: { INCLUDE_NODEJS_FUNCTION_LAMBDA: '1', INCLUDE_SINGLE_BUCKET: '0', RETAIN_SINGLE_BUCKET: '0' },
});
const cfnTemplateBeforeImport = await fixture.aws.cloudFormation.send(
new GetTemplateCommand({ StackName: fullStackName }),
);
expect(cfnTemplateBeforeImport.TemplateBody).not.toContain(bucketLogicalId);

// WHEN
await fixture.cdk(['import', '--resource-mapping', mappingFile, fixture.fullStackName('importable-stack')], {
modEnv: { INCLUDE_NODEJS_FUNCTION_LAMBDA: '1', INCLUDE_SINGLE_BUCKET: '1', RETAIN_SINGLE_BUCKET: '0' },
});

// THEN
const describeStacksResponse = await fixture.aws.cloudFormation.send(
new DescribeStacksCommand({ StackName: fullStackName }),
);
const cfnTemplateAfterImport = await fixture.aws.cloudFormation.send(
new GetTemplateCommand({ StackName: fullStackName }),
);

// If bundling is skipped during import for NodeJSFunction lambda, then the operation should fail and exit
expect(describeStacksResponse.Stacks![0].StackStatus).toEqual('IMPORT_COMPLETE');

// If the import operation is successful, the template should contain the imported bucket
expect(cfnTemplateAfterImport.TemplateBody).toContain(bucketLogicalId);
} finally {
// Clean up the resources we created
await fixture.cdkDestroy('importable-stack');
}
}),
);

/**
* Create a queue, orphan that queue, then import the queue.
*
Expand Down

0 comments on commit 076dcdd

Please sign in to comment.