-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(codedeploy) lambda application and deployment groups (#1628)
Adds `LambdaApplication` and `LambdaDeploymentGroup` such that an `Alias` to a Lambda `Function` can be deployed via CodeDeploy; supports pre/post hook functions, traffic-shifting and alarm monitoring and rollback.
- Loading branch information
Sam Goodwin
authored
Feb 4, 2019
1 parent
1d705e7
commit 4c4b015
Showing
27 changed files
with
2,001 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export * from './application'; | ||
export * from './deployment-config'; | ||
export * from './deployment-group'; | ||
export * from './rollback-config'; | ||
export * from './lambda'; | ||
export * from './pipeline-action'; | ||
export * from './server'; | ||
|
||
// AWS::CodeDeploy CloudFormation Resources: | ||
export * from './codedeploy.generated'; |
101 changes: 101 additions & 0 deletions
101
packages/@aws-cdk/aws-codedeploy/lib/lambda/application.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import cdk = require("@aws-cdk/cdk"); | ||
import { CfnApplication } from "../codedeploy.generated"; | ||
import { applicationNameToArn } from "../utils"; | ||
|
||
/** | ||
* Represents a reference to a CodeDeploy Application deploying to AWS Lambda. | ||
* | ||
* If you're managing the Application alongside the rest of your CDK resources, | ||
* use the {@link LambdaApplication} class. | ||
* | ||
* If you want to reference an already existing Application, | ||
* or one defined in a different CDK Stack, | ||
* use the {@link LambdaApplication#import} method. | ||
*/ | ||
export interface ILambdaApplication extends cdk.IConstruct { | ||
readonly applicationArn: string; | ||
readonly applicationName: string; | ||
|
||
export(): LambdaApplicationImportProps; | ||
} | ||
|
||
/** | ||
* Construction properties for {@link LambdaApplication}. | ||
*/ | ||
export interface LambdaApplicationProps { | ||
/** | ||
* The physical, human-readable name of the CodeDeploy Application. | ||
* | ||
* @default an auto-generated name will be used | ||
*/ | ||
applicationName?: string; | ||
} | ||
|
||
/** | ||
* A CodeDeploy Application that deploys to an AWS Lambda function. | ||
*/ | ||
export class LambdaApplication extends cdk.Construct implements ILambdaApplication { | ||
/** | ||
* Import an Application defined either outside the CDK, | ||
* or in a different CDK Stack and exported using the {@link ILambdaApplication#export} method. | ||
* | ||
* @param scope the parent Construct for this new Construct | ||
* @param id the logical ID of this new Construct | ||
* @param props the properties of the referenced Application | ||
* @returns a Construct representing a reference to an existing Application | ||
*/ | ||
public static import(scope: cdk.Construct, id: string, props: LambdaApplicationImportProps): ILambdaApplication { | ||
return new ImportedLambdaApplication(scope, id, props); | ||
} | ||
|
||
public readonly applicationArn: string; | ||
public readonly applicationName: string; | ||
|
||
constructor(scope: cdk.Construct, id: string, props: LambdaApplicationProps = {}) { | ||
super(scope, id); | ||
|
||
const resource = new CfnApplication(this, 'Resource', { | ||
applicationName: props.applicationName, | ||
computePlatform: 'Lambda' | ||
}); | ||
|
||
this.applicationName = resource.ref; | ||
this.applicationArn = applicationNameToArn(this.applicationName, this); | ||
} | ||
|
||
public export(): LambdaApplicationImportProps { | ||
return { | ||
applicationName: new cdk.Output(this, 'ApplicationName', { value: this.applicationName }).makeImportValue().toString() | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Properties of a reference to a CodeDeploy Application. | ||
* | ||
* @see LambdaApplication#import | ||
* @see ILambdaApplication#export | ||
*/ | ||
export interface LambdaApplicationImportProps { | ||
/** | ||
* The physical, human-readable name of the Lambda Application we're referencing. | ||
* The Application must be in the same account and region as the root Stack. | ||
*/ | ||
applicationName: string; | ||
} | ||
|
||
class ImportedLambdaApplication extends cdk.Construct implements ILambdaApplication { | ||
public readonly applicationArn: string; | ||
public readonly applicationName: string; | ||
|
||
constructor(scope: cdk.Construct, id: string, private readonly props: LambdaApplicationImportProps) { | ||
super(scope, id); | ||
|
||
this.applicationName = props.applicationName; | ||
this.applicationArn = applicationNameToArn(props.applicationName, this); | ||
} | ||
|
||
public export(): LambdaApplicationImportProps { | ||
return this.props; | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
packages/@aws-cdk/aws-codedeploy/lib/lambda/deployment-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { arnForDeploymentConfigName } from '../utils'; | ||
|
||
/** | ||
* The Deployment Configuration of a Lambda Deployment Group. | ||
* The default, pre-defined Configurations are available as constants on the {@link LambdaDeploymentConfig} class | ||
* (`LambdaDeploymentConfig.AllAtOnce`, `LambdaDeploymentConfig.Canary10Percent30Minutes`, etc.). | ||
* | ||
* Note: CloudFormation does not currently support creating custom lambda configs outside | ||
* of using a custom resource. You can import custom deployment config created outside the | ||
* CDK or via a custom resource with {@link LambdaDeploymentConfig#import}. | ||
*/ | ||
export interface ILambdaDeploymentConfig { | ||
readonly deploymentConfigName: string; | ||
deploymentConfigArn(scope: cdk.IConstruct): string; | ||
} | ||
|
||
class DefaultLambdaDeploymentConfig implements ILambdaDeploymentConfig { | ||
public readonly deploymentConfigName: string; | ||
|
||
constructor(deploymentConfigName: string) { | ||
this.deploymentConfigName = `CodeDeployDefault.Lambda${deploymentConfigName}`; | ||
} | ||
|
||
public deploymentConfigArn(scope: cdk.IConstruct): string { | ||
return arnForDeploymentConfigName(this.deploymentConfigName, scope); | ||
} | ||
} | ||
|
||
/** | ||
* Properties of a reference to a CodeDeploy Lambda Deployment Configuration. | ||
* | ||
* @see LambdaDeploymentConfig#import | ||
* @see LambdaDeploymentConfig#export | ||
*/ | ||
export interface LambdaDeploymentConfigImportProps { | ||
/** | ||
* The physical, human-readable name of the custom CodeDeploy Lambda Deployment Configuration | ||
* that we are referencing. | ||
*/ | ||
deploymentConfigName: string; | ||
} | ||
|
||
class ImportedLambdaDeploymentConfig extends cdk.Construct implements ILambdaDeploymentConfig { | ||
public readonly deploymentConfigName: string; | ||
|
||
constructor(scope: cdk.Construct, id: string, private readonly props: LambdaDeploymentConfigImportProps) { | ||
super(scope, id); | ||
|
||
this.deploymentConfigName = props.deploymentConfigName; | ||
} | ||
|
||
public deploymentConfigArn(scope: cdk.IConstruct): string { | ||
return arnForDeploymentConfigName(this.deploymentConfigName, scope); | ||
} | ||
|
||
public export() { | ||
return this.props; | ||
} | ||
} | ||
|
||
/** | ||
* A custom Deployment Configuration for a Lambda Deployment Group. | ||
* | ||
* Note: This class currently stands as namespaced container of the default configurations | ||
* until CloudFormation supports custom Lambda Deployment Configs. Until then it is closed | ||
* (private constructor) and does not extend {@link cdk.Construct} | ||
*/ | ||
export class LambdaDeploymentConfig { | ||
public static readonly AllAtOnce: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('AllAtOnce'); | ||
public static readonly Canary10Percent30Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Canary10Percent30Minutes'); | ||
public static readonly Canary10Percent5Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Canary10Percent5Minutes'); | ||
public static readonly Canary10Percent10Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Canary10Percent10Minutes'); | ||
public static readonly Canary10Percent15Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Canary10Percent15Minutes'); | ||
public static readonly Linear10PercentEvery10Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Linear10PercentEvery10Minutes'); | ||
public static readonly Linear10PercentEvery1Minute: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Linear10PercentEvery1Minute'); | ||
public static readonly Linear10PercentEvery2Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Linear10PercentEvery2Minutes'); | ||
public static readonly Linear10PercentEvery3Minutes: ILambdaDeploymentConfig = new DefaultLambdaDeploymentConfig('Linear10PercentEvery3Minutes'); | ||
|
||
/** | ||
* Import a custom Deployment Configuration for a Lambda Deployment Group defined outside the CDK. | ||
* | ||
* @param scope the parent Construct for this new Construct | ||
* @param id the logical ID of this new Construct | ||
* @param props the properties of the referenced custom Deployment Configuration | ||
* @returns a Construct representing a reference to an existing custom Deployment Configuration | ||
*/ | ||
public static import(scope: cdk.Construct, id: string, props: LambdaDeploymentConfigImportProps): ILambdaDeploymentConfig { | ||
return new ImportedLambdaDeploymentConfig(scope, id, props); | ||
} | ||
|
||
private constructor() { | ||
// nothing to do until CFN supports custom lambda deployment configurations | ||
} | ||
} |
Oops, something went wrong.