Skip to content

Commit

Permalink
Merge branch 'main' into comcalvi/cfn-include-drops-stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 3, 2024
2 parents f565701 + 0e03d39 commit 6545b91
Show file tree
Hide file tree
Showing 234 changed files with 134,447 additions and 128,565 deletions.
18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,24 @@ grantAwesomePowerBeta1()
When we decide it's time to graduate the API, the latest preview version will
be deprecated and the final version - `grantAwesomePower` will be added.

### Adding new experimental CLI features

In order to move fast when developing new CLI features, we may decide to release
functionality as "experimental" or "incremental." In this scenario we can utilize
explicit opt-in via an `--unstable` flag.

Explicit opt-ins would look something like this:

```bash
cdk new-command --unstable='new-command'

cdk bootstrap --unstable='new-funky-bootstrap'
```

And can be simply added as an additional flag on the CLI command that is being worked on.
When the time comes to stabilize the command, we remove the requirement that such a flag
is set.

## Documentation

Every module's README is rendered as the landing page of the official documentation. For example, this is
Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ Shout out to our top contributors!
- [mrgrain](https://github.com/mrgrain)
- [pahud](https://github.com/pahud)
- [TheRealAmazonKendra](https://github.com/TheRealAmazonKendra)
- [madeline-k](https://github.com/madeline-k)
- [comcalvi](https://github.com/comcalvi)
- [madeline-k](https://github.com/madeline-k)
- [NetaNir](https://github.com/NetaNir)
- [robertd](https://github.com/robertd)
- [MrArnoldPalmer](https://github.com/MrArnoldPalmer)
- [go-to-k](https://github.com/go-to-k)
- [MrArnoldPalmer](https://github.com/MrArnoldPalmer)
- [lpizzinidev](https://github.com/lpizzinidev)
- [peterwoodworth](https://github.com/peterwoodworth)
- [mazyu36](https://github.com/mazyu36)
- [colifran](https://github.com/colifran)
- [badmintoncryer](https://github.com/badmintoncryer)
- [msambol](https://github.com/msambol)
- [mazyu36](https://github.com/mazyu36)
- [watany-dev](https://github.com/watany-dev)
- [badmintoncryer](https://github.com/badmintoncryer)


_Last updated: Sun, 01 Sep 24 00:12:30 +0000_
_Last updated: Tue, 01 Oct 24 00:12:17 +0000_
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
19 changes: 17 additions & 2 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
24 changes: 24 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 @@ -72,6 +72,13 @@ class YourStack extends cdk.Stack {
}
}

class NoticesStack extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);
new sqs.Queue(this, 'queue');
}
}

class SsoPermissionSetNoPolicy extends Stack {
constructor(scope, id) {
super(scope, id);
Expand Down Expand Up @@ -424,6 +431,20 @@ class LambdaStack extends cdk.Stack {
}
}

class IamRolesStack extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, props);

// 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}`, {
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
});
}
}
}

class SessionTagsStack extends cdk.Stack {
constructor(parent, id, props) {
super(parent, id, {
Expand Down Expand Up @@ -753,6 +774,7 @@ switch (stackSet) {
// Deploy all does a wildcard ${stackPrefix}-test-*
new MyStack(app, `${stackPrefix}-test-1`, { env: defaultEnv });
new YourStack(app, `${stackPrefix}-test-2`);
new NoticesStack(app, `${stackPrefix}-notices`);
// Deploy wildcard with parameters does ${stackPrefix}-param-test-*
new ParameterStack(app, `${stackPrefix}-param-test-1`);
new OtherParameterStack(app, `${stackPrefix}-param-test-2`);
Expand All @@ -770,6 +792,8 @@ switch (stackSet) {

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

new IamRolesStack(app, `${stackPrefix}-iam-roles`);

if (process.env.ENABLE_VPC_TESTING == 'IMPORT') {
// this stack performs a VPC lookup so we gate synth
const env = { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION };
Expand Down
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 6545b91

Please sign in to comment.