Skip to content

Commit

Permalink
Merge branch 'main' into merge-back/2.63.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Feb 4, 2023
2 parents e08e34a + 2b6a0be commit 83d1685
Show file tree
Hide file tree
Showing 171 changed files with 7,903 additions and 6,316 deletions.
4 changes: 4 additions & 0 deletions .gitallowed
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ account: '012345678913'

# Account patterns used in the CHANGELOG
account: '123456789012'

111111111111
222222222222
123456789012
333333333333

# The account ID's of public facing ECR images for App Mesh Envoy
# https://docs.aws.amazon.com/app-mesh/latest/userguide/envoy.html
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/close-stale-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on:
schedule:
# Cron format: min hr day month dow
- cron: "0 0 * * *"
workflow_dispatch:
workflow_dispatch:
jobs:
close-stale-prs:
permissions:
Expand All @@ -23,5 +23,5 @@ jobs:
important-checks-regex: AutoBuildv2Project1C6BFA3F
warn-message: This PR has been in the STATE state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.
close-message: This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.
skip-labels: contribution/core
skip-labels: contribution/core, pr-linter/do-not-close
close-label: closed-for-staleness
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"devDependencies": {
"@types/prettier": "2.6.0",
"@yarnpkg/lockfile": "^1.1.0",
"cdk-generate-synthetic-examples": "^0.1.138",
"cdk-generate-synthetic-examples": "^0.1.140",
"conventional-changelog-cli": "^2.2.2",
"fs-extra": "^9.1.0",
"graceful-fs": "^4.2.10",
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class EcsDeploymentGroup extends DeploymentGroupBase implements IEcsDeplo
this.alarms = props.alarms || [];

this.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSCodeDeployRoleForECS'));
this.deploymentConfig = props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE);

if (cdk.Resource.isOwnedResource(props.service)) {
const cfnSvc = (props.service as ecs.BaseService).node.defaultChild as ecs.CfnService;
Expand Down Expand Up @@ -358,6 +358,6 @@ class ImportedEcsDeploymentGroup extends ImportedDeploymentGroupBase implements
});

this.application = props.application;
this.deploymentConfig = props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class LambdaDeploymentGroup extends DeploymentGroupBase implements ILambd
this.alarms = props.alarms || [];

this.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSCodeDeployRoleForLambdaLimited'));
this.deploymentConfig = props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES);

const resource = new CfnDeploymentGroup(this, 'Resource', {
applicationName: this.application.applicationName,
Expand Down Expand Up @@ -290,6 +290,6 @@ class ImportedLambdaDeploymentGroup extends ImportedDeploymentGroupBase implemen
});

this.application = props.application;
this.deploymentConfig = props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as iam from '@aws-cdk/aws-iam';
import { Resource, IResource, ArnFormat, Arn, Aws } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { IBaseDeploymentConfig } from '../base-deployment-config';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { isPredefinedDeploymentConfig } from './predefined-deployment-config';
import { validateName } from './utils';

/**
Expand Down Expand Up @@ -52,6 +54,15 @@ export class ImportedDeploymentGroupBase extends Resource {
this.deploymentGroupName = deploymentGroupName;
this.deploymentGroupArn = deploymentGroupArn;
}

/**
* Bind DeploymentGroupConfig to the current group, if supported
*
* @internal
*/
protected _bindDeploymentConfig(config: IBaseDeploymentConfig) {
return isPredefinedDeploymentConfig(config) ? config.bindEnvironment(this) : config;
}
}

export interface DeploymentGroupBaseProps {
Expand Down Expand Up @@ -114,6 +125,15 @@ export class DeploymentGroupBase extends Resource {
this.node.addValidation({ validate: () => validateName('Deployment group', this.physicalName) });
}

/**
* Bind DeploymentGroupConfig to the current group, if supported
*
* @internal
*/
protected _bindDeploymentConfig(config: IBaseDeploymentConfig) {
return isPredefinedDeploymentConfig(config) ? config.bindEnvironment(this) : config;
}

/**
* Set name and ARN properties.
*
Expand All @@ -135,4 +155,4 @@ export class DeploymentGroupBase extends Resource {
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { IResource } from '@aws-cdk/core';
import { IBaseDeploymentConfig } from '../base-deployment-config';

/**
* A reference to a DeploymentConfig that is managed by AWS
*
* Since these DeploymentConfigs are present in every region, and we might use
* them in conjunction with cross-region DeploymentGroups, we need to specialize
* the account and region to the DeploymentGroup before using.
*
* A DeploymentGroup must call `bindEnvironment()` first if it detects this type,
* before reading the DeploymentConfig ARN.
*
* This type is fully hidden, which means that the constant objects provided by
* CDK will have magical behavior that customers can't reimplement themselves.
* Not ideal, but our DeploymentConfig type inheritance is already overly
* complicated and to do it properly with the nominal typing we are emplying
* will require adding 4 more empty or nearly empty interfaces, which seems a
* bit silly for a need that's not necessarily clearly needed by customers.
* We can always move to exposing later.
*/
export interface IPredefinedDeploymentConfig {
/**
* Bind the predefined deployment config to the environment of the given resource
*/
bindEnvironment(deploymentGroup: IResource): IBaseDeploymentConfig;
}

export function isPredefinedDeploymentConfig(x: unknown): x is IPredefinedDeploymentConfig {
return typeof x === 'object' && !!x && !!(x as any).bindEnvironment;
}
15 changes: 10 additions & 5 deletions packages/@aws-cdk/aws-codedeploy/lib/private/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import { Token, Stack, ArnFormat, Arn, Fn, Aws } from '@aws-cdk/core';
import { Token, Stack, ArnFormat, Arn, Fn, Aws, IResource } from '@aws-cdk/core';
import { IBaseDeploymentConfig } from '../base-deployment-config';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { AutoRollbackConfig } from '../rollback-config';
import { IPredefinedDeploymentConfig } from './predefined-deployment-config';

export function arnForApplication(stack: Stack, applicationName: string): string {
return stack.formatArn({
Expand All @@ -18,11 +19,11 @@ export function nameFromDeploymentGroupArn(deploymentGroupArn: string): string {
return Fn.select(1, Fn.split('/', components.resourceName ?? ''));
}

export function arnForDeploymentConfig(name: string): string {
export function arnForDeploymentConfig(name: string, resource?: IResource): string {
return Arn.format({
partition: Aws.PARTITION,
account: Aws.ACCOUNT_ID,
region: Aws.REGION,
account: resource?.env.account ?? Aws.ACCOUNT_ID,
region: resource?.env.region ?? Aws.REGION,
service: 'codedeploy',
resource: 'deploymentconfig',
resourceName: name,
Expand All @@ -41,10 +42,14 @@ CfnDeploymentGroup.AlarmConfigurationProperty | undefined {
};
}

export function deploymentConfig(name: string): IBaseDeploymentConfig {
export function deploymentConfig(name: string): IBaseDeploymentConfig & IPredefinedDeploymentConfig {
return {
deploymentConfigName: name,
deploymentConfigArn: arnForDeploymentConfig(name),
bindEnvironment: (resource) => ({
deploymentConfigName: name,
deploymentConfigArn: arnForDeploymentConfig(name, resource),
}),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ImportedServerDeploymentGroup extends ImportedDeploymentGroupBase implemen
});

this.application = props.application;
this.deploymentConfig = props.deploymentConfig || ServerDeploymentConfig.ONE_AT_A_TIME;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || ServerDeploymentConfig.ONE_AT_A_TIME);
}
}

Expand Down Expand Up @@ -255,7 +255,7 @@ export class ServerDeploymentGroup extends DeploymentGroupBase implements IServe
this.application = props.application || new ServerApplication(this, 'Application', {
applicationName: props.deploymentGroupName === cdk.PhysicalName.GENERATE_IF_NEEDED ? cdk.PhysicalName.GENERATE_IF_NEEDED : undefined,
});
this.deploymentConfig = props.deploymentConfig || ServerDeploymentConfig.ONE_AT_A_TIME;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || ServerDeploymentConfig.ONE_AT_A_TIME);

this.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSCodeDeployRole'));
this._autoScalingGroups = props.autoScalingGroups || [];
Expand Down
47 changes: 28 additions & 19 deletions packages/@aws-cdk/aws-codedeploy/test/ecs/deployment-group.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as ecs from '@aws-cdk/aws-ecs';
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';
import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import { Duration } from '@aws-cdk/core';
import { Duration, Stack } from '@aws-cdk/core';
import * as codedeploy from '../../lib';

const mockCluster = 'my-cluster';
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('CodeDeploy ECS DeploymentGroup', () => {
deploymentGroupName: 'EcsDeploymentGroup',
});

expect(importedGroup.deploymentConfig).toEqual(codedeploy.EcsDeploymentConfig.ALL_AT_ONCE);
expect(importedGroup.deploymentConfig.deploymentConfigName).toEqual('CodeDeployDefault.ECSAllAtOnce');
});
});

Expand Down Expand Up @@ -849,25 +849,34 @@ describe('CodeDeploy ECS DeploymentGroup', () => {
});
});

test('deploymentGroup from Arn knows its account and region', () => {
// GIVEN
const stack = new cdk.Stack(undefined, 'Stack', { env: { account: '111111111111', region: 'blabla-1' } });
describe('deploymentGroup from ARN in different account and region', () => {
let stack: Stack;
let application: codedeploy.IEcsApplication;
let group: codedeploy.IEcsDeploymentGroup;

// WHEN
const application = codedeploy.EcsApplication.fromEcsApplicationArn(stack, 'Application', 'arn:aws:codedeploy:theregion-1:222222222222:application:MyApplication');
const group = codedeploy.EcsDeploymentGroup.fromEcsDeploymentGroupAttributes(stack, 'Group', {
application,
deploymentGroupName: 'DeploymentGroup',
const account = '222222222222';
const region = 'theregion-1';

beforeEach(() => {
stack = new cdk.Stack(undefined, 'Stack', { env: { account: '111111111111', region: 'blabla-1' } });

application = codedeploy.EcsApplication.fromEcsApplicationArn(stack, 'Application', `arn:aws:codedeploy:${region}:${account}:application:MyApplication`);
group = codedeploy.EcsDeploymentGroup.fromEcsDeploymentGroupAttributes(stack, 'Group', {
application,
deploymentGroupName: 'DeploymentGroup',
});
});

// THEN
expect(application.env).toEqual(expect.objectContaining({
account: '222222222222',
region: 'theregion-1',
}));
expect(group.env).toEqual(expect.objectContaining({
account: '222222222222',
region: 'theregion-1',
}));
test('knows its account and region', () => {
// THEN
expect(application.env).toEqual(expect.objectContaining({ account, region }));
expect(group.env).toEqual(expect.objectContaining({ account, region }));
});

test('references the predefined DeploymentGroupConfig in the right region', () => {
expect(group.deploymentConfig.deploymentConfigArn).toEqual(expect.stringContaining(
`:codedeploy:${region}:${account}:deploymentconfig:CodeDeployDefault.ECSAllAtOnce`,
));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
import * as iam from '@aws-cdk/aws-iam';
import * as lambda from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
import { Stack } from '@aws-cdk/core';
import * as codedeploy from '../../lib';
import { TrafficRouting } from '../../lib';

Expand Down Expand Up @@ -616,26 +617,35 @@ describe('CodeDeploy Lambda DeploymentGroup', () => {
});
});

test('deploymentGroup from Arn knows its account and region', () => {
// GIVEN
const stack = new cdk.Stack(undefined, 'Stack', { env: { account: '111111111111', region: 'blabla-1' } });
describe('deploymentGroup from ARN in different account and region', () => {
let stack: Stack;
let application: codedeploy.ILambdaApplication;
let group: codedeploy.ILambdaDeploymentGroup;

// WHEN
const application = codedeploy.LambdaApplication.fromLambdaApplicationArn(stack, 'Application', 'arn:aws:codedeploy:theregion-1:222222222222:application:MyApplication');
const group = codedeploy.LambdaDeploymentGroup.fromLambdaDeploymentGroupAttributes(stack, 'Group', {
application,
deploymentGroupName: 'DeploymentGroup',
});

// THEN
expect(application.env).toEqual(expect.objectContaining({
account: '222222222222',
region: 'theregion-1',
}));
expect(group.env).toEqual(expect.objectContaining({
account: '222222222222',
region: 'theregion-1',
}));
const account = '222222222222';
const region = 'theregion-1';

beforeEach(() => {
stack = new cdk.Stack(undefined, 'Stack', { env: { account: '111111111111', region: 'blabla-1' } });

application = codedeploy.LambdaApplication.fromLambdaApplicationArn(stack, 'Application', `arn:aws:codedeploy:${region}:${account}:application:MyApplication`);
group = codedeploy.LambdaDeploymentGroup.fromLambdaDeploymentGroupAttributes(stack, 'Group', {
application,
deploymentGroupName: 'DeploymentGroup',
});
});

test('knows its account and region', () => {
// THEN
expect(application.env).toEqual(expect.objectContaining({ account, region }));
expect(group.env).toEqual(expect.objectContaining({ account, region }));
});

test('references the predefined DeploymentGroupConfig in the right region', () => {
expect(group.deploymentConfig.deploymentConfigArn).toEqual(expect.stringContaining(
`:codedeploy:${region}:${account}:deploymentconfig:CodeDeployDefault.LambdaCanary10Percent5Minutes`,
));
});
});
});

Expand All @@ -649,7 +659,7 @@ describe('imported with fromLambdaDeploymentGroupAttributes', () => {
deploymentGroupName: 'LambdaDeploymentGroup',
});

expect(importedGroup.deploymentConfig).toEqual(codedeploy.LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES);
expect(importedGroup.deploymentConfig.deploymentConfigName).toEqual('CodeDeployDefault.LambdaCanary10Percent5Minutes');
});
});

Expand Down
Loading

0 comments on commit 83d1685

Please sign in to comment.