Skip to content

Commit b614e01

Browse files
authored
Merge branch 'main' into docs-fix-appsync-events-apikey
2 parents 27e854f + 331d7a5 commit b614e01

File tree

20 files changed

+350
-258
lines changed

20 files changed

+350
-258
lines changed

packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/cli.integtest.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { AssumeRoleCommand, GetCallerIdentityCommand } from '@aws-sdk/client-sts
2525
import {
2626
cloneDirectory,
2727
integTest,
28-
// randomInteger,
28+
randomInteger,
2929
randomString,
3030
RESOURCES_DIR,
3131
retry,
@@ -2214,26 +2214,26 @@ integTest(
22142214
}),
22152215
);
22162216

2217-
// integTest(
2218-
// 'sam can locally test the synthesized cdk application',
2219-
// withSamIntegrationFixture(async (fixture) => {
2220-
// // Synth first
2221-
// await fixture.cdkSynth();
2222-
2223-
// const result = await fixture.samLocalStartApi(
2224-
// 'TestStack',
2225-
// false,
2226-
// randomInteger(30000, 40000),
2227-
// '/restapis/spec/pythonFunction',
2228-
// );
2229-
// expect(result.actionSucceeded).toBeTruthy();
2230-
// expect(result.actionOutput).toEqual(
2231-
// expect.objectContaining({
2232-
// message: 'Hello World',
2233-
// }),
2234-
// );
2235-
// }),
2236-
// );
2217+
integTest(
2218+
'sam can locally test the synthesized cdk application',
2219+
withSamIntegrationFixture(async (fixture) => {
2220+
// Synth first
2221+
await fixture.cdkSynth();
2222+
2223+
const result = await fixture.samLocalStartApi(
2224+
'TestStack',
2225+
false,
2226+
randomInteger(30000, 40000),
2227+
'/restapis/spec/pythonFunction',
2228+
);
2229+
expect(result.actionSucceeded).toBeTruthy();
2230+
expect(result.actionOutput).toEqual(
2231+
expect.objectContaining({
2232+
message: 'Hello World',
2233+
}),
2234+
);
2235+
}),
2236+
);
22372237

22382238
integTest(
22392239
'skips notice refresh',
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
const baseConfig = require('@aws-cdk/cdk-build-tools/config/jest.config');
22
module.exports = {
33
...baseConfig,
4+
randomize: true,
45
coverageThreshold: {
56
global: {
67
// this is very sad but we will get better
7-
branches: 42,
8-
statements: 69,
8+
statements: 75,
9+
branches: 55,
10+
functions: 70,
11+
lines: 75,
912
},
1013
},
1114
};

packages/@aws-cdk/toolkit/lib/actions/deploy/index.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ export interface BaseDeployOptions {
115115
*/
116116
readonly stacks?: StackSelector;
117117

118-
/**
119-
* @deprecated set on toolkit
120-
* Name of the toolkit stack to use/deploy
121-
*
122-
* @default CDKToolkit
123-
*/
124-
readonly toolkitStackName?: string;
125-
126118
/**
127119
* Role to pass to CloudFormation for deployment
128120
*/

packages/@aws-cdk/toolkit/lib/api/aws-cdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export { Deployments, type SuccessfulDeployStackResult } from '../../../../aws-c
77
export { Settings } from '../../../../aws-cdk/lib/api/settings';
88
export { tagsForStack } from '../../../../aws-cdk/lib/api/tags';
99
export { DEFAULT_TOOLKIT_STACK_NAME } from '../../../../aws-cdk/lib/api/toolkit-info';
10+
export { ResourceMigrator } from '../../../../aws-cdk/lib/api/resource-import';
1011

1112
// Context Providers
1213
export * as contextproviders from '../../../../aws-cdk/lib/context-providers';
@@ -19,7 +20,6 @@ export { formatTime } from '../../../../aws-cdk/lib/api/util/string-manipulation
1920

2021
// @todo Not yet API probably should be
2122
export { formatErrorMessage } from '../../../../aws-cdk/lib/util/error';
22-
export { ResourceMigrator } from '../../../../aws-cdk/lib/migrator';
2323
export { obscureTemplate, serializeStructure } from '../../../../aws-cdk/lib/serialize';
2424
export { loadTree, some } from '../../../../aws-cdk/lib/tree';
2525
export { splitBySize } from '../../../../aws-cdk/lib/util';

packages/@aws-cdk/toolkit/lib/api/io/private/codes.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ export const CODES = {
1515
// 2: List
1616
CDK_TOOLKIT_I2901: 'Provides details on the selected stacks and their dependencies',
1717

18+
// 3: Import & Migrate
19+
CDK_TOOLKIT_E3900: 'Resource import failed',
20+
1821
// 4: Diff
1922

20-
// 5: Deploy
23+
// 5: Deploy & Watch
2124
CDK_TOOLKIT_I5000: 'Provides deployment times',
2225
CDK_TOOLKIT_I5001: 'Provides total time in deploy action, including synth and rollback',
26+
CDK_TOOLKIT_I5002: 'Provides time for resource migration',
2327
CDK_TOOLKIT_I5031: 'Informs about any log groups that are traced as part of the deployment',
2428
CDK_TOOLKIT_I5050: 'Confirm rollback during deployment',
2529
CDK_TOOLKIT_I5060: 'Confirm deploy security sensitive changes',

packages/@aws-cdk/toolkit/lib/toolkit/toolkit.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { CachedCloudAssemblySource, IdentityCloudAssemblySource, StackAssembly,
1919
import { ALL_STACKS, CloudAssemblySourceBuilder } from '../api/cloud-assembly/private';
2020
import { ToolkitError } from '../api/errors';
2121
import { IIoHost, IoMessageCode, IoMessageLevel } from '../api/io';
22-
import { asSdkLogger, withAction, Timer, confirm, error, highlight, info, success, warn, ActionAwareIoHost, debug, result, withoutEmojis, withoutColor, withTrimmedWhitespace } from '../api/io/private';
22+
import { asSdkLogger, withAction, Timer, confirm, error, info, success, warn, ActionAwareIoHost, debug, result, withoutEmojis, withoutColor, withTrimmedWhitespace } from '../api/io/private';
2323

2424
/**
2525
* The current action being performed by the CLI. 'none' represents the absence of an action.
@@ -256,10 +256,8 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
256256
}
257257

258258
const deployments = await this.deploymentsForAction('deploy');
259+
const migrator = new ResourceMigrator({ deployments, ioHost, action });
259260

260-
const migrator = new ResourceMigrator({
261-
deployments,
262-
});
263261
await migrator.tryMigrateResources(stackCollection, options);
264262

265263
const requireApproval = options.requireApproval ?? RequireApproval.NEVER;
@@ -275,7 +273,6 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
275273
}
276274

277275
const stacks = stackCollection.stackArtifacts;
278-
279276
const stackOutputs: { [key: string]: any } = {};
280277
const outputsFile = options.outputsFile;
281278

@@ -303,28 +300,31 @@ export class Toolkit extends CloudAssemblySourceBuilder implements AsyncDisposab
303300
const deployStack = async (stackNode: StackNode) => {
304301
const stack = stackNode.stack;
305302
if (stackCollection.stackCount !== 1) {
306-
await ioHost.notify(highlight(stack.displayName));
303+
await ioHost.notify(info(chalk.bold(stack.displayName)));
307304
}
308305

309306
if (!stack.environment) {
310-
// eslint-disable-next-line max-len
311307
throw new ToolkitError(
312308
`Stack ${stack.displayName} does not define an environment, and AWS credentials could not be obtained from standard locations or no region was configured.`,
313309
);
314310
}
315311

312+
// The generated stack has no resources
316313
if (Object.keys(stack.template.Resources || {}).length === 0) {
317-
// The generated stack has no resources
318-
if (!(await deployments.stackExists({ stack }))) {
319-
await ioHost.notify(warn(`${chalk.bold(stack.displayName)}: stack has no resources, skipping deployment.`));
320-
} else {
321-
await ioHost.notify(warn(`${chalk.bold(stack.displayName)}: stack has no resources, deleting existing stack.`));
322-
await this._destroy(assembly, 'deploy', {
323-
stacks: { patterns: [stack.hierarchicalId], strategy: StackSelectionStrategy.PATTERN_MUST_MATCH_SINGLE },
324-
roleArn: options.roleArn,
325-
ci: options.ci,
326-
});
314+
// stack is empty and doesn't exist => do nothing
315+
const stackExists = await deployments.stackExists({ stack });
316+
if (!stackExists) {
317+
return ioHost.notify(warn(`${chalk.bold(stack.displayName)}: stack has no resources, skipping deployment.`));
327318
}
319+
320+
// stack is empty, but exists => delete
321+
await ioHost.notify(warn(`${chalk.bold(stack.displayName)}: stack has no resources, deleting existing stack.`));
322+
await this._destroy(assembly, 'deploy', {
323+
stacks: { patterns: [stack.hierarchicalId], strategy: StackSelectionStrategy.PATTERN_MUST_MATCH_SINGLE },
324+
roleArn: options.roleArn,
325+
ci: options.ci,
326+
});
327+
328328
return;
329329
}
330330

packages/@aws-cdk/toolkit/test/_fixtures/stack-with-asset/asset/index.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/@aws-cdk/toolkit/test/_fixtures/stack-with-asset/index.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/@aws-cdk/toolkit/test/actions/destroy.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const ioHost = new TestIoHost();
77
const toolkit = new Toolkit({ ioHost });
88
jest.spyOn(toolkit, 'rollback').mockResolvedValue();
99

10-
let mockDestroyStack = jest.fn().mockResolvedValue({});
10+
let mockDestroyStack = jest.fn();
1111

1212
jest.mock('../../lib/api/aws-cdk', () => {
1313
return {
@@ -22,6 +22,7 @@ beforeEach(() => {
2222
ioHost.notifySpy.mockClear();
2323
ioHost.requestSpy.mockClear();
2424
jest.clearAllMocks();
25+
mockDestroyStack.mockResolvedValue({});
2526
});
2627

2728
describe('destroy', () => {
@@ -68,7 +69,7 @@ describe('destroy', () => {
6869

6970
test('destroy deployment fails', async () => {
7071
// GIVEN
71-
mockDestroyStack = jest.fn().mockRejectedValue({});
72+
mockDestroyStack.mockRejectedValue({});
7273

7374
// WHEN
7475
const cx = await builderFixture(toolkit, 'stack-with-role');

packages/@aws-cdk/toolkit/test/actions/rollback.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import { builderFixture, TestIoHost } from '../_helpers';
55
const ioHost = new TestIoHost();
66
const toolkit = new Toolkit({ ioHost });
77

8-
let mockRollbackStack = jest.fn().mockResolvedValue({
9-
notInRollbackableState: false,
10-
success: true,
11-
});
12-
8+
let mockRollbackStack = jest.fn();
139
jest.mock('../../lib/api/aws-cdk', () => {
1410
return {
1511
...jest.requireActual('../../lib/api/aws-cdk'),
@@ -23,6 +19,10 @@ beforeEach(() => {
2319
ioHost.notifySpy.mockClear();
2420
ioHost.requestSpy.mockClear();
2521
jest.clearAllMocks();
22+
mockRollbackStack.mockResolvedValue({
23+
notInRollbackableState: false,
24+
success: true,
25+
});
2626
});
2727

2828
describe('rollback', () => {

0 commit comments

Comments
 (0)