Skip to content

Commit

Permalink
Merge branch 'main' into pipes-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
msambol authored Oct 8, 2024
2 parents b53dab2 + 642a944 commit c4a4daa
Show file tree
Hide file tree
Showing 174 changed files with 48,775 additions and 5,009 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/request-cli-integ-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
persist-credentials: false
- name: Find changed cli files
id: changed-cli-files
uses: tj-actions/changed-files@48d8f15b2aaa3d255ca5af3eba4870f807ce6b3c
uses: tj-actions/changed-files@c3a1bb2c992d77180ae65be6ae6c166cf40f857c
with:
base_sha: ${{ github.event.pull_request.base.sha }}
files_yaml: |
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7484,10 +7484,10 @@ const bucket = new s3.Bucket(this, 'L2Bucket');
const bucketResource = bucket.findChild('Resource') as s3.cloudformation.BucketResource;

// strongly-typed overrides
bucketResource.propertyOverrides.bucketName = 'NewBucketName';
bucketResource.propertyOverrides.bucketName = 'amzn-s3-demo-bucket';

// weakly-typed overrides
bucketResource.addPropertyOverride('BucketName', 'NewerBucketName');
bucketResource.addPropertyOverride('BucketName', 'amzn-s3-demo-bucket1');
```

### Bug Fixes
Expand Down Expand Up @@ -8289,7 +8289,7 @@ new Pipeline(this, 'MyCoolPipeline', { artifactsBucket: bucket });
You can also import a bucket by just specifying its name:

```typescript
const bucket = Bucket.import({ bucketName: new BucketName('my-bucket') });
const bucket = Bucket.import({ bucketName: new BucketName('amzn-s3-demo-bucket') });
new Pipeline(this, 'MyCoolPipeline', { artifactsBucket: bucket });
```

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"colors": "1.4.0",
"markdown-it": "^12.3.2",
"string-width": "^4.2.3",
"@types/babel__traverse": "7.18.2"
"@types/babel__traverse": "7.18.2",
"@smithy/types": "3.5.0"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk-testing/cli-integ/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Test suites are written as a collection of Jest tests, and they are run using Je

### Setup

Building the @aws-cdk-testing package is not very different from building the rest of the CDK. However, If you are having issues with the tests, you can ensure your enviornment is built properly by following the steps below:
Building the @aws-cdk-testing package is not very different from building the rest of the CDK. However, If you are having issues with the tests, you can ensure your environment is built properly by following the steps below:

```shell
yarn install # Install dependencies
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk-testing/cli-integ/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
DeleteStackCommand,
DescribeStacksCommand,
UpdateTerminationProtectionCommand,
Stack,
type Stack,
} from '@aws-sdk/client-cloudformation';
import { DeleteRepositoryCommand, ECRClient } from '@aws-sdk/client-ecr';
import { ECSClient } from '@aws-sdk/client-ecs';
Expand All @@ -13,14 +13,14 @@ import {
S3Client,
DeleteObjectsCommand,
ListObjectVersionsCommand,
ObjectIdentifier,
type ObjectIdentifier,
DeleteBucketCommand,
} from '@aws-sdk/client-s3';
import { SNSClient } from '@aws-sdk/client-sns';
import { SSOClient } from '@aws-sdk/client-sso';
import { STSClient, GetCallerIdentityCommand } from '@aws-sdk/client-sts';
import { fromIni } from '@aws-sdk/credential-providers';
import { AwsCredentialIdentityProvider } from '@smithy/types';
import type { AwsCredentialIdentityProvider } from '@smithy/types';
import { ConfiguredRetryStrategy } from '@smithy/util-retry';
interface ClientConfig {
readonly credentials?: AwsCredentialIdentityProvider;
Expand Down Expand Up @@ -75,7 +75,7 @@ export class AwsClients {
maxAttempts: 2,
});

return (await stsClient.send(new GetCallerIdentityCommand())).Account!;
return (await stsClient.send(new GetCallerIdentityCommand({}))).Account!;
}

public async deleteStacks(...stackNames: string[]) {
Expand Down
26 changes: 23 additions & 3 deletions packages/@aws-cdk-testing/cli-integ/lib/with-cdk-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const EXTENDED_TEST_TIMEOUT_S = 30 * 60;
* For backwards compatibility with existing tests (so we don't have to change
* too much) the inner block is expected to take a `TestFixture` object.
*/
export function withCdkApp(
export function withSpecificCdkApp(
appName: string,
block: (context: TestFixture) => Promise<void>,
): (context: TestContext & AwsContext & DisableBootstrapContext) => Promise<void> {
return async (context: TestContext & AwsContext & DisableBootstrapContext) => {
Expand All @@ -36,7 +37,7 @@ export function withCdkApp(
context.output.write(` Test directory: ${integTestDir}\n`);
context.output.write(` Region: ${context.aws.region}\n`);

await cloneDirectory(path.join(RESOURCES_DIR, 'cdk-apps', 'app'), integTestDir, context.output);
await cloneDirectory(path.join(RESOURCES_DIR, 'cdk-apps', appName), integTestDir, context.output);
const fixture = new TestFixture(
integTestDir,
stackNamePrefix,
Expand Down Expand Up @@ -87,6 +88,16 @@ export function withCdkApp(
};
}

/**
* Like `withSpecificCdkApp`, but uses the default integration testing app with a million stacks in it
*/
export function withCdkApp(
block: (context: TestFixture) => Promise<void>,
): (context: TestContext & AwsContext & DisableBootstrapContext) => Promise<void> {
// 'app' is the name of the default integration app in the `cdk-apps` directory
return withSpecificCdkApp('app', block);
}

export function withCdkMigrateApp<A extends TestContext>(language: string, block: (context: TestFixture) => Promise<void>) {
return async (context: A) => {
const stackName = `cdk-migrate-${language}-integ-${context.randomString}`;
Expand Down Expand Up @@ -188,6 +199,10 @@ export function withDefaultFixture(block: (context: TestFixture) => Promise<void
return withAws(withTimeout(DEFAULT_TEST_TIMEOUT_S, withCdkApp(block)));
}

export function withSpecificFixture(appName: string, block: (context: TestFixture) => Promise<void>) {
return withAws(withTimeout(DEFAULT_TEST_TIMEOUT_S, withSpecificCdkApp(appName, block)));
}

export function withExtendedTimeoutFixture(block: (context: TestFixture) => Promise<void>) {
return withAws(withTimeout(EXTENDED_TEST_TIMEOUT_S, withCdkApp(block)));
}
Expand Down Expand Up @@ -258,6 +273,11 @@ interface CommonCdkBootstrapCommandOptions {
* @default - none
*/
readonly tags?: string;

/**
* @default - the default CDK qualifier
*/
readonly qualifier?: string;
}

export interface CdkLegacyBootstrapCommandOptions extends CommonCdkBootstrapCommandOptions {
Expand Down Expand Up @@ -408,7 +428,7 @@ export class TestFixture extends ShellHelper {
if (options.bootstrapBucketName) {
args.push('--bootstrap-bucket-name', options.bootstrapBucketName);
}
args.push('--qualifier', this.qualifier);
args.push('--qualifier', options.qualifier ?? this.qualifier);
if (options.cfnExecutionPolicy) {
args.push('--cloudformation-execution-policies', options.cfnExecutionPolicy);
}
Expand Down
26 changes: 13 additions & 13 deletions packages/@aws-cdk-testing/cli-integ/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@
},
"dependencies": {
"@octokit/rest": "^18.12.0",
"@aws-sdk/client-codeartifact": "3.637.0",
"@aws-sdk/client-cloudformation": "3.637.0",
"@aws-sdk/client-ecr": "3.637.0",
"@aws-sdk/client-ecs": "3.637.0",
"@aws-sdk/client-iam": "3.637.0",
"@aws-sdk/client-lambda": "3.637.0",
"@aws-sdk/client-s3": "3.637.0",
"@aws-sdk/client-sns": "3.637.0",
"@aws-sdk/client-sso": "3.637.0",
"@aws-sdk/client-sts": "3.637.0",
"@aws-sdk/credential-providers": "3.637.0",
"@smithy/util-retry": "3.0.4",
"@smithy/types": "3.4.0",
"@aws-sdk/client-codeartifact": "3.632.0",
"@aws-sdk/client-cloudformation": "3.632.0",
"@aws-sdk/client-ecr": "3.632.0",
"@aws-sdk/client-ecs": "3.632.0",
"@aws-sdk/client-iam": "3.632.0",
"@aws-sdk/client-lambda": "3.632.0",
"@aws-sdk/client-s3": "3.632.0",
"@aws-sdk/client-sns": "3.632.0",
"@aws-sdk/client-sso": "3.632.0",
"@aws-sdk/client-sts": "3.632.0",
"@aws-sdk/credential-providers": "3.632.0",
"@smithy/util-retry": "3.0.7",
"@smithy/types": "3.5.0",
"axios": "^1.7.7",
"chalk": "^4",
"fs-extra": "^9.1.0",
Expand Down
20 changes: 15 additions & 5 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 @@ -35,7 +35,7 @@ if (process.env.PACKAGE_LAYOUT_VERSION === '1') {
}

const { Annotations } = cdk;
const { StackWithNestedStack, StackWithNestedStackUsingParameters } = require('./nested-stack');
const { StackWithNestedStack, StackWithDoublyNestedStack, StackWithNestedStackUsingParameters } = require('./nested-stack');

const stackPrefix = process.env.STACK_NAME_PREFIX;
if (!stackPrefix) {
Expand Down Expand Up @@ -176,7 +176,7 @@ class DependentStack extends Stack {
super(scope, id);

const innerDependentStack = new InnerDependentStack(this, 'InnerDependentStack');

this.addDependency(innerDependentStack);
}
}
Expand Down Expand Up @@ -204,7 +204,7 @@ class MigrateStack extends cdk.Stack {
new cdk.CfnOutput(this, 'QueueUrl', {
value: queue.queueUrl,
});

new cdk.CfnOutput(this, 'QueueLogicalId', {
value: queue.node.defaultChild.logicalId,
});
Expand Down Expand Up @@ -258,7 +258,7 @@ class ImportableStack extends cdk.Stack {
new cdk.CfnOutput(this, 'QueueUrl', {
value: queue.queueUrl,
});

new cdk.CfnOutput(this, 'QueueLogicalId', {
value: queue.node.defaultChild.logicalId,
});
Expand Down Expand Up @@ -438,9 +438,17 @@ class IamRolesStack extends cdk.Stack {
// Environment variabile is used to create a bunch of roles to test
// that large diff templates are uploaded to S3 to create the changeset.
for(let i = 1; i <= Number(process.env.NUMBER_OF_ROLES) ; i++) {
new iam.Role(this, `Role${i}`, {
const role = new iam.Role(this, `Role${i}`, {
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
});
const cfnRole = role.node.defaultChild;

// For any extra IAM roles created, add a ton of metadata so that the template size is > 50 KiB.
if (i > 1) {
for(let i = 1; i <= 30 ; i++) {
cfnRole.addMetadata('a'.repeat(1000), 'v');
}
}
}
}
}
Expand Down Expand Up @@ -792,6 +800,7 @@ switch (stackSet) {

new LambdaStack(app, `${stackPrefix}-lambda`);

// This stack is used to test diff with large templates by creating a role with a ton of metadata
new IamRolesStack(app, `${stackPrefix}-iam-roles`);

if (process.env.ENABLE_VPC_TESTING == 'IMPORT') {
Expand Down Expand Up @@ -835,6 +844,7 @@ switch (stackSet) {

new StackWithNestedStack(app, `${stackPrefix}-with-nested-stack`);
new StackWithNestedStackUsingParameters(app, `${stackPrefix}-with-nested-stack-using-parameters`);
new StackWithDoublyNestedStack(app, `${stackPrefix}-with-doubly-nested-stack`);
new ListStack(app, `${stackPrefix}-list-stacks`)
new ListMultipleDependentStack(app, `${stackPrefix}-list-multiple-dependent-stacks`);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ class MyNestedStack extends cfn.NestedStack {
}
}

class DoublyNestedStack extends cfn.NestedStack {
constructor(scope, id) {
super(scope, id);

new MyNestedStack(this, 'Nestor');
}
}

class StackWithDoublyNestedStack extends Stack {
constructor(scope, id) {
super(scope, id);
new DoublyNestedStack(this, 'DoubleDouble');
}
}

class StackWithNestedStackUsingParameters extends Stack {
constructor(scope, id) {
super(scope, id);
Expand All @@ -47,3 +62,4 @@ class MyNestedStackUsingParameters extends cfn.NestedStack {

exports.StackWithNestedStack = StackWithNestedStack;
exports.StackWithNestedStackUsingParameters = StackWithNestedStackUsingParameters;
exports.StackWithDoublyNestedStack = StackWithDoublyNestedStack;
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const cdk = require('aws-cdk-lib');
const lambda = require('aws-cdk-lib/aws-lambda');
const cr = require('aws-cdk-lib/custom-resources');

/**
* This stack will be deployed in multiple phases, to achieve a very specific effect
*
* It contains resources r1 and r2, where r1 gets deployed first.
*
* - PHASE = 1: both resources deploy regularly.
* - PHASE = 2a: r1 gets updated, r2 will fail to update
* - PHASE = 2b: r1 gets updated, r2 will fail to update, and r1 will fail its rollback.
*
* To exercise this app:
*
* ```
* env PHASE=1 npx cdk deploy
* env PHASE=2b npx cdk deploy --no-rollback
* # This will leave the stack in UPDATE_FAILED
*
* env PHASE=2b npx cdk rollback
* # This will start a rollback that will fail because r1 fails its rollabck
*
* env PHASE=2b npx cdk rollback --force
* # This will retry the rollabck and skip r1
* ```
*/
class RollbacktestStack extends cdk.Stack {
constructor(scope, id, props) {
super(scope, id, props);

let r1props = {};
let r2props = {};

const phase = process.env.PHASE;
switch (phase) {
case '1':
// Normal deployment
break;
case '2a':
// r1 updates normally, r2 fails updating
r2props.FailUpdate = true;
break;
case '2b':
// r1 updates normally, r2 fails updating, r1 fails rollback
r1props.FailRollback = true;
r2props.FailUpdate = true;
break;
}

const fn = new lambda.Function(this, 'Fun', {
runtime: lambda.Runtime.NODEJS_LATEST,
code: lambda.Code.fromInline(`exports.handler = async function(event, ctx) {
const key = \`Fail\${event.RequestType}\`;
if (event.ResourceProperties[key]) {
throw new Error(\`\${event.RequestType} fails!\`);
}
if (event.OldResourceProperties?.FailRollback) {
throw new Error('Failing rollback!');
}
return {};
}`),
handler: 'index.handler',
timeout: cdk.Duration.minutes(1),
});
const provider = new cr.Provider(this, "MyProvider", {
onEventHandler: fn,
});

const r1 = new cdk.CustomResource(this, 'r1', {
serviceToken: provider.serviceToken,
properties: r1props,
});
const r2 = new cdk.CustomResource(this, 'r2', {
serviceToken: provider.serviceToken,
properties: r2props,
});
r2.node.addDependency(r1);
}
}

const app = new cdk.App({
context: {
'@aws-cdk/core:assetHashSalt': process.env.CODEBUILD_BUILD_ID, // Force all assets to be unique, but consistent in one build
},
});

const defaultEnv = {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION
};

const stackPrefix = process.env.STACK_NAME_PREFIX;
if (!stackPrefix) {
throw new Error(`the STACK_NAME_PREFIX environment variable is required`);
}

// Sometimes we don't want to synthesize all stacks because it will impact the results
new RollbacktestStack(app, `${stackPrefix}-test-rollback`, { env: defaultEnv });
app.synth();
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"app": "node app.js",
"versionReporting": false,
"context": {
"aws-cdk:enableDiffNoFail": "true"
}
}
Loading

0 comments on commit c4a4daa

Please sign in to comment.