Skip to content

Commit

Permalink
Add AtDeploymentTick extension action point to AppConfig resource con…
Browse files Browse the repository at this point in the history
…structs
  • Loading branch information
cpaluch-aws committed Dec 4, 2024
1 parent bf77e51 commit 97dd6f3
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 9 deletions.
20 changes: 20 additions & 0 deletions packages/aws-cdk-lib/aws-appconfig/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ export interface IApplication extends cdk.IResource {
*/
onDeploymentRolledBack(eventDestination: IEventDestination, options?: ExtensionOptions): void;

/**
* Adds an AT_DEPLOYMENT_TICK extension with the provided event destination and
* also creates an extension association to an application.
*
* @param eventDestination The event that occurs during the extension
* @param options Options for the extension
*/
atDeploymentTick(eventDestination: IEventDestination, options?: ExtensionOptions): void;

/**
* Adds an extension association to the application.
*
Expand Down Expand Up @@ -297,6 +306,17 @@ abstract class ApplicationBase extends cdk.Resource implements IApplication, IEx
this.extensible.onDeploymentRolledBack(eventDestination, options);
}

/**
* Adds an AT_DEPLOYMENT_TICK extension with the provided event destination and
* also creates an extension association to an application.
*
* @param eventDestination The event that occurs during the extension
* @param options Options for the extension
*/
public atDeploymentTick(eventDestination: IEventDestination, options?: ExtensionOptions) {
this.extensible.atDeploymentTick(eventDestination, options);
}

/**
* Adds an extension association to the application.
*
Expand Down
11 changes: 11 additions & 0 deletions packages/aws-cdk-lib/aws-appconfig/lib/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ abstract class ConfigurationBase extends Construct implements IConfiguration, IE
this.extensible.onDeploymentRolledBack(eventDestination, options);
}

/**
* Adds an AT_DEPLOYMENT_TICK extension with the provided event destination and
* also creates an extension association to an application.
*
* @param eventDestination The event that occurs during the extension
* @param options Options for the extension
*/
public atDeploymentTick(eventDestination: IEventDestination, options?: ExtensionOptions) {
this.extensible.atDeploymentTick(eventDestination, options);
}

/**
* Adds an extension association to the configuration profile.
*
Expand Down
13 changes: 13 additions & 0 deletions packages/aws-cdk-lib/aws-appconfig/lib/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ abstract class EnvironmentBase extends Resource implements IEnvironment, IExtens
this.extensible.onDeploymentRolledBack(eventDestination, options);
}

public atDeploymentTick(eventDestination: IEventDestination, options?: ExtensionOptions) {
this.extensible.atDeploymentTick(eventDestination, options);
}

public addExtension(extension: IExtension) {
this.extensible.addExtension(extension);
}
Expand Down Expand Up @@ -556,6 +560,15 @@ export interface IEnvironment extends IResource {
*/
onDeploymentRolledBack(eventDestination: IEventDestination, options?: ExtensionOptions): void;

/**
* Adds an AT_DEPLOYMENT_TICK extension with the provided event destination and
* also creates an extension association to an application.
*
* @param eventDestination The event that occurs during the extension
* @param options Options for the extension
*/
atDeploymentTick(eventDestination: IEventDestination, options?: ExtensionOptions): void;

/**
* Adds an extension association to the environment.
*
Expand Down
14 changes: 14 additions & 0 deletions packages/aws-cdk-lib/aws-appconfig/lib/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum ActionPoint {
ON_DEPLOYMENT_BAKING = 'ON_DEPLOYMENT_BAKING',
ON_DEPLOYMENT_COMPLETE = 'ON_DEPLOYMENT_COMPLETE',
ON_DEPLOYMENT_ROLLED_BACK = 'ON_DEPLOYMENT_ROLLED_BACK',
AT_DEPLOYMENT_TICK = 'AT_DEPLOYMENT_TICK',
}

/**
Expand Down Expand Up @@ -657,6 +658,10 @@ export class ExtensibleBase implements IExtensible {
this.getExtensionForActionPoint(eventDestination, ActionPoint.ON_DEPLOYMENT_ROLLED_BACK, options);
}

public atDeploymentTick(eventDestination: IEventDestination, options?: ExtensionOptions) {
this.getExtensionForActionPoint(eventDestination, ActionPoint.AT_DEPLOYMENT_TICK, options);
}

public addExtension(extension: IExtension) {
this.addExtensionAssociation(extension);
}
Expand Down Expand Up @@ -793,6 +798,15 @@ export interface IExtensible {
*/
onDeploymentRolledBack(eventDestination: IEventDestination, options?: ExtensionOptions): void;

/**
* Adds an AT_DEPLOYMENT_TICK extension with the provided event destination and
* also creates an extension association to the derived resource.
*
* @param eventDestination The event that occurs during the extension
* @param options Options for the extension
*/
atDeploymentTick(eventDestination: IEventDestination, options?: ExtensionOptions): void;

/**
* Adds an extension association to the derived resource.
*
Expand Down
68 changes: 59 additions & 9 deletions packages/aws-cdk-lib/aws-appconfig/test/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('appconfig', () => {
const appconfig = new Application(stack, 'MyAppConfig');
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
appconfig.on(ActionPoint.ON_DEPLOYMENT_STEP, new LambdaDestination(func));
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('appconfig', () => {
const appconfig = new Application(stack, 'MyAppConfig');
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
appconfig.preCreateHostedConfigurationVersion(new LambdaDestination(func), {
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('appconfig', () => {
const appconfig = new Application(stack, 'MyAppConfig');
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
Object.defineProperty(func, 'functionArn', {
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('appconfig', () => {
});
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
Object.defineProperty(func, 'functionArn', {
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('appconfig', () => {
const appconfig = new Application(stack, 'MyAppConfig');
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
Object.defineProperty(func, 'functionArn', {
Expand Down Expand Up @@ -331,7 +331,7 @@ describe('appconfig', () => {
const appconfig = new Application(stack, 'MyAppConfig');
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
Object.defineProperty(func, 'functionArn', {
Expand Down Expand Up @@ -381,7 +381,7 @@ describe('appconfig', () => {
const appconfig = new Application(stack, 'MyAppConfig');
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
Object.defineProperty(func, 'functionArn', {
Expand Down Expand Up @@ -431,7 +431,7 @@ describe('appconfig', () => {
const appconfig = new Application(stack, 'MyAppConfig');
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
Object.defineProperty(func, 'functionArn', {
Expand Down Expand Up @@ -476,12 +476,62 @@ describe('appconfig', () => {
});
});

test('at deployment tick', () => {
const stack = new cdk.Stack();
const appconfig = new Application(stack, 'MyAppConfig');
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
Object.defineProperty(func, 'functionArn', {
value: 'arn:lambda:us-east-1:123456789012:function:my-function',
});
appconfig.atDeploymentTick(new LambdaDestination(func));

Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::Extension', {
Name: 'MyAppConfig-Extension',
Actions: {
AT_DEPLOYMENT_TICK: [
{
Name: 'MyAppConfig-Extension-0',
RoleArn: { 'Fn::GetAtt': ['MyAppConfigExtensionF845ERole0D30970E5A7E5', 'Arn'] },
Uri: 'arn:lambda:us-east-1:123456789012:function:my-function',
},
],
},
});
Template.fromStack(stack).hasResourceProperties('AWS::AppConfig::ExtensionAssociation', {
ExtensionIdentifier: {
'Fn::GetAtt': ['MyAppConfigExtensionF845EC11D4079', 'Id'],
},
ExtensionVersionNumber: {
'Fn::GetAtt': ['MyAppConfigExtensionF845EC11D4079', 'VersionNumber'],
},
ResourceIdentifier: {
'Fn::Join': [
'',
[
'arn:',
{ Ref: 'AWS::Partition' },
':appconfig:',
{ Ref: 'AWS::Region' },
':',
{ Ref: 'AWS::AccountId' },
':application/',
{ Ref: 'MyAppConfigB4B63E75' },
],
],
},
});
});

test('create same extension twice', () => {
const stack = new cdk.Stack();
const appconfig = new Application(stack, 'MyAppConfig');
const func = new Function(stack, 'MyFunc', {
handler: 'index.handler',
runtime: Runtime.PYTHON_3_7,
runtime: Runtime.PYTHON_3_9,
code: Code.fromInline('# this is my code'),
});
Object.defineProperty(func, 'functionArn', {
Expand Down
8 changes: 8 additions & 0 deletions packages/aws-cdk-lib/aws-appconfig/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ describe('extension', () => {
actionPoints: [
ActionPoint.ON_DEPLOYMENT_COMPLETE,
ActionPoint.ON_DEPLOYMENT_ROLLED_BACK,
ActionPoint.AT_DEPLOYMENT_TICK,
],
eventDestination: new LambdaDestination(func),
}),
Expand All @@ -56,6 +57,13 @@ describe('extension', () => {
Uri: { 'Fn::GetAtt': ['MyFunction3BAA72D1', 'Arn'] },
},
],
AT_DEPLOYMENT_TICK: [
{
Name: 'MyExtension-0',
RoleArn: { 'Fn::GetAtt': ['MyExtensionRole467D6FCDEEFA5', 'Arn'] },
Uri: { 'Fn::GetAtt': ['MyFunction3BAA72D1', 'Arn'] },
},
],
},
});
Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', {
Expand Down
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/awslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@
"docs-public-apis:aws-cdk-lib.aws_appconfig.ActionPoint.ON_DEPLOYMENT_BAKING",
"docs-public-apis:aws-cdk-lib.aws_appconfig.ActionPoint.ON_DEPLOYMENT_COMPLETE",
"docs-public-apis:aws-cdk-lib.aws_appconfig.ActionPoint.ON_DEPLOYMENT_ROLLED_BACK",
"docs-public-apis:aws-cdk-lib.aws_appconfig.ActionPoint.AT_DEPLOYMENT_TICK",
"docs-public-apis:aws-cdk-lib.aws_appconfig.IValidator",
"docs-public-apis:aws-cdk-lib.aws_appconfig.IExtension",
"docs-public-apis:aws-cdk-lib.aws_appconfig.IEnvironment",
Expand Down

0 comments on commit 97dd6f3

Please sign in to comment.