Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(appconfig): fromDeploymentStrategyId takes an enum-like class rather than a string #28743

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-appconfig-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ new appconfig.DeploymentStrategy(this, 'MyDeploymentStrategy', {
});
```

Importing a deployment strategy by ID:

```ts
appconfig.DeploymentStrategy.fromDeploymentStrategyId(this, 'MyImportedDeploymentStrategy', appconfig.DeploymentStrategyId.fromString('abc123'));
```

Importing an AWS AppConfig predefined deployment strategy by ID:

```ts
appconfig.DeploymentStrategy.fromDeploymentStrategyId(this, 'MyImportedPredefinedDeploymentStrategy', appconfig.DeploymentStrategyId.CANARY_10_PERCENT_20_MINUTES);
kaizencc marked this conversation as resolved.
Show resolved Hide resolved
```

## Configuration

A configuration is a higher-level construct that can either be a `HostedConfiguration` (stored internally through AWS
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-appconfig-alpha/awslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
"docs-public-apis:@aws-cdk/aws-appconfig-alpha.IConfiguration",
"docs-public-apis:@aws-cdk/aws-appconfig-alpha.IApplication",

"no-unused-type:@aws-cdk/aws-appconfig-alpha.PredefinedDeploymentStrategyId",
"ref-via-interface:@aws-cdk/aws-appconfig-alpha.Application.addAgentToEcs.taskDef",
"props-physical-name:@aws-cdk/aws-appconfig-alpha.ApplicationProps",
"props-physical-name:@aws-cdk/aws-appconfig-alpha.DeploymentStrategyProps",
"props-physical-name:@aws-cdk/aws-appconfig-alpha.EnvironmentProps",
"props-physical-name:@aws-cdk/aws-appconfig-alpha.ExtensionProps",
"events-in-interface",
"events-method-signature",
"events-generic"
"events-generic",
"from-signature:@aws-cdk/aws-appconfig-alpha.DeploymentStrategy.fromDeploymentStrategyId.params[2]"
]
}
34 changes: 25 additions & 9 deletions packages/@aws-cdk/aws-appconfig-alpha/lib/deployment-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ export class DeploymentStrategy extends Resource implements IDeploymentStrategy
* @param id The name of the deployment strategy construct
* @param deploymentStrategyId The ID of the deployment strategy
*/
public static fromDeploymentStrategyId(scope: Construct, id: string, deploymentStrategyId: string): IDeploymentStrategy {
public static fromDeploymentStrategyId(scope: Construct, id: string, deploymentStrategyId: DeploymentStrategyId): IDeploymentStrategy {
const stack = Stack.of(scope);
const deploymentStrategyArn = stack.formatArn({
service: 'appconfig',
resource: 'deploymentstrategy',
resourceName: deploymentStrategyId,
resourceName: deploymentStrategyId.id,
});

class Import extends Resource implements IDeploymentStrategy {
public readonly deploymentStrategyId = deploymentStrategyId;
public readonly deploymentStrategyId = deploymentStrategyId.id;
public readonly deploymentStrategyArn = deploymentStrategyArn;
}

Expand Down Expand Up @@ -182,36 +182,52 @@ export enum GrowthType {
}

/**
* Defines the deployment strategy ID's of AWS AppConfig predefined strategies.
* Defines the deployment strategy ID's of AWS AppConfig deployment strategies.
*
* @see https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-creating-deployment-strategy.html
*/
export enum PredefinedDeploymentStrategyId {
export abstract class DeploymentStrategyId {
/**
* **AWS Recommended**. This strategy processes the deployment exponentially using a 10% growth factor over 20 minutes.
* AWS AppConfig recommends using this strategy for production deployments because it aligns with AWS best practices
* for configuration deployments.
*/
CANARY_10_PERCENT_20_MINUTES = 'AppConfig.Canary10Percent20Minutes',
public static readonly CANARY_10_PERCENT_20_MINUTES = DeploymentStrategyId.fromString('AppConfig.Canary10Percent20Minutes');

/**
* **Testing/Demonstration**. This strategy deploys the configuration to half of all targets every 30 seconds for a
* one-minute deployment. AWS AppConfig recommends using this strategy only for testing or demonstration purposes because
* it has a short duration and bake time.
*/
LINEAR_50_PERCENT_EVERY_30_SECONDS = 'AppConfig.Linear50PercentEvery30Seconds',
public static readonly LINEAR_50_PERCENT_EVERY_30_SECONDS = DeploymentStrategyId.fromString('AppConfig.Linear50PercentEvery30Seconds');

/**
* **AWS Recommended**. This strategy deploys the configuration to 20% of all targets every six minutes for a 30 minute deployment.
* AWS AppConfig recommends using this strategy for production deployments because it aligns with AWS best practices
* for configuration deployments.
*/
LINEAR_20_PERCENT_EVERY_6_MINUTES = 'AppConfig.Linear20PercentEvery6Minutes',
public static readonly LINEAR_20_PERCENT_EVERY_6_MINUTES = DeploymentStrategyId.fromString('AppConfig.Linear20PercentEvery6Minutes');

/**
* **Quick**. This strategy deploys the configuration to all targets immediately.
*/
ALL_AT_ONCE = 'AppConfig.AllAtOnce',
public static readonly ALL_AT_ONCE = DeploymentStrategyId.fromString('AppConfig.AllAtOnce');

/**
* Builds a deployment strategy ID from a string.
*
* @param deploymentStrategyId The deployment strategy ID.
*/
public static fromString(deploymentStrategyId: string): DeploymentStrategyId {
return {
id: deploymentStrategyId,
};
}

/**
* The deployment strategy ID.
*/
public abstract readonly id: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as cdk from 'aws-cdk-lib';
import { App } from 'aws-cdk-lib';
import { Template } from 'aws-cdk-lib/assertions';
import { DeploymentStrategy, PredefinedDeploymentStrategyId, RolloutStrategy } from '../lib';
import { DeploymentStrategy, DeploymentStrategyId, RolloutStrategy } from '../lib';

describe('deployment strategy', () => {
test('default deployment strategy', () => {
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('deployment strategy', () => {
account: '123456789012',
},
});
const deploymentStrategy = DeploymentStrategy.fromDeploymentStrategyId(stack, 'MyDeploymentStrategy', 'abc123');
const deploymentStrategy = DeploymentStrategy.fromDeploymentStrategyId(stack, 'MyDeploymentStrategy', DeploymentStrategyId.fromString('abc123'));

expect(deploymentStrategy.deploymentStrategyId).toEqual('abc123');
expect(deploymentStrategy.env.account).toEqual('123456789012');
Expand All @@ -181,7 +181,7 @@ describe('deployment strategy', () => {
account: '123456789012',
},
});
const deploymentStrategy = DeploymentStrategy.fromDeploymentStrategyId(stack, 'MyDeploymentStrategy', PredefinedDeploymentStrategyId.ALL_AT_ONCE);
const deploymentStrategy = DeploymentStrategy.fromDeploymentStrategyId(stack, 'MyDeploymentStrategy', DeploymentStrategyId.ALL_AT_ONCE);

expect(deploymentStrategy.deploymentStrategyId).toEqual('AppConfig.AllAtOnce');
expect(deploymentStrategy.env.account).toEqual('123456789012');
Expand All @@ -196,7 +196,7 @@ describe('deployment strategy', () => {
account: '123456789012',
},
});
const deploymentStrategy = DeploymentStrategy.fromDeploymentStrategyId(stack, 'MyDeploymentStrategy', PredefinedDeploymentStrategyId.CANARY_10_PERCENT_20_MINUTES);
const deploymentStrategy = DeploymentStrategy.fromDeploymentStrategyId(stack, 'MyDeploymentStrategy', DeploymentStrategyId.CANARY_10_PERCENT_20_MINUTES);

expect(deploymentStrategy.deploymentStrategyId).toEqual('AppConfig.Canary10Percent20Minutes');
expect(deploymentStrategy.env.account).toEqual('123456789012');
Expand All @@ -211,7 +211,7 @@ describe('deployment strategy', () => {
account: '123456789012',
},
});
const deploymentStrategy = DeploymentStrategy.fromDeploymentStrategyId(stack, 'MyDeploymentStrategy', PredefinedDeploymentStrategyId.LINEAR_50_PERCENT_EVERY_30_SECONDS);
const deploymentStrategy = DeploymentStrategy.fromDeploymentStrategyId(stack, 'MyDeploymentStrategy', DeploymentStrategyId.LINEAR_50_PERCENT_EVERY_30_SECONDS);

expect(deploymentStrategy.deploymentStrategyId).toEqual('AppConfig.Linear50PercentEvery30Seconds');
expect(deploymentStrategy.env.account).toEqual('123456789012');
Expand Down
Loading