Skip to content

Commit

Permalink
use default qualifier
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed May 31, 2024
1 parent 6f8742d commit bfab0e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
24 changes: 9 additions & 15 deletions packages/sandbox/src/file_watching_sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { afterEach, beforeEach, describe, it, mock } from 'node:test';
import path from 'path';
import watcher from '@parcel/watcher';
import {
CDK_BOOTSTRAP_VERSION_PARAMETER_PREFIX,
CDK_BOOTSTRAP_VERSION_PARAMETER_SUFFIX,
CDK_DEFAULT_BOOTSTRAP_VERSION_PARAMETER_NAME,
FileWatchingSandbox,
getBootstrapUrl,
} from './file_watching_sandbox.js';
Expand All @@ -29,7 +28,6 @@ import { fileURLToPath } from 'url';
import { BackendIdentifier } from '@aws-amplify/plugin-types';
import { AmplifyUserError } from '@aws-amplify/platform-core';
import { SSMClient } from '@aws-sdk/client-ssm';
import { randomUUID } from 'node:crypto';

// Watcher mocks
const unsubscribeMockFn = mock.fn();
Expand Down Expand Up @@ -91,12 +89,10 @@ const ssmClientSendMock = mock.fn();
mock.method(ssmClientMock, 'send', ssmClientSendMock);
ssmClientSendMock.mock.mockImplementation(() =>
Promise.resolve({
Parameters: [
{
Name: `${CDK_BOOTSTRAP_VERSION_PARAMETER_PREFIX}${randomUUID()}${CDK_BOOTSTRAP_VERSION_PARAMETER_SUFFIX}`,
Value: '18',
},
],
Parameter: {
Name: CDK_DEFAULT_BOOTSTRAP_VERSION_PARAMETER_NAME,
Value: '18',
},
})
);
const openMock = mock.fn(_open, (url: string) => Promise.resolve(url));
Expand Down Expand Up @@ -178,12 +174,10 @@ void describe('Sandbox to check if region is bootstrapped', () => {
void it('when region has bootstrapped, but with a version lower than the minimum (6), then opens console to initiate bootstrap', async () => {
ssmClientSendMock.mock.mockImplementationOnce(() =>
Promise.resolve({
Parameters: [
{
Name: `${CDK_BOOTSTRAP_VERSION_PARAMETER_PREFIX}${randomUUID()}${CDK_BOOTSTRAP_VERSION_PARAMETER_SUFFIX}`,
Value: '5',
},
],
Parameter: {
Name: CDK_DEFAULT_BOOTSTRAP_VERSION_PARAMETER_NAME,
Value: '5',
},
})
);

Expand Down
30 changes: 19 additions & 11 deletions packages/sandbox/src/file_watching_sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import _open from 'open';
// EventEmitter is a class name and expected to have PascalCase
// eslint-disable-next-line @typescript-eslint/naming-convention
import EventEmitter from 'events';
import { GetParametersByPathCommand, SSMClient } from '@aws-sdk/client-ssm';
import { GetParameterCommand, SSMClient } from '@aws-sdk/client-ssm';
import {
AmplifyPrompter,
LogLevel,
Expand All @@ -32,9 +32,20 @@ import {
BackendIdentifierConversions,
} from '@aws-amplify/platform-core';

// CDK stores bootstrap version in parameter store. Example parameter name looks like /cdk-bootstrap/<hash>/version
export const CDK_BOOTSTRAP_VERSION_PARAMETER_PREFIX = '/cdk-bootstrap/';
export const CDK_BOOTSTRAP_VERSION_PARAMETER_SUFFIX = '/version';
/**
* CDK stores bootstrap version in parameter store. Example parameter name looks like /cdk-bootstrap/<qualifier>/version.
* The default value for qualifier is hnb659fds, i.e. default parameter path is /cdk-bootstrap/hnb659fds/version.
* The default qualifier is hardcoded value without any significance.
* Ability to provide custom qualifier is intended for name isolation between automated tests of the CDK itself.
* In order to use custom qualifier all stack synthesizers must be programmatically configured to use it.
* That makes bootstraps with custom qualifier incompatible with Amplify Backend and we treat that setup as
* not bootstrapped.
* See: https://docs.aws.amazon.com/cdk/v2/guide/bootstrapping.html
*/
export const CDK_DEFAULT_BOOTSTRAP_VERSION_PARAMETER_NAME =
// suppress spell checker, it is triggered by qualifier value.
// eslint-disable-next-line spellcheck/spell-checker
'/cdk-bootstrap/hnb659fds/version';
export const CDK_MIN_BOOTSTRAP_VERSION = 6;

/**
Expand Down Expand Up @@ -296,16 +307,13 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox {
*/
private isBootstrapped = async () => {
try {
const { Parameters: parameters } = await this.ssmClient.send(
new GetParametersByPathCommand({
Path: CDK_BOOTSTRAP_VERSION_PARAMETER_PREFIX,
Recursive: true,
const { Parameter: parameter } = await this.ssmClient.send(
new GetParameterCommand({
Name: CDK_DEFAULT_BOOTSTRAP_VERSION_PARAMETER_NAME,
})
);

const bootstrapVersion = parameters?.find((parameter) =>
parameter?.Name?.endsWith(CDK_BOOTSTRAP_VERSION_PARAMETER_SUFFIX)
)?.Value;
const bootstrapVersion = parameter?.Value;
if (
!bootstrapVersion ||
Number(bootstrapVersion) < CDK_MIN_BOOTSTRAP_VERSION
Expand Down

0 comments on commit bfab0e8

Please sign in to comment.