Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
yarn-error.log
lerna-debug.log

# Ignore user config files
.vscode/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"retryAppConfig": {
"max": {
"__name": "RETRY_APPCONFIG_MAX",
"__format": "number"
},
"base": {
"__name": "RETRY_APPCONFIG_BASE_MS",
"__format": "number"
}
},
"retryS3": {
"max": {
"__name": "RETRY_S3_MAX",
"__format": "number"
},
"base": {
"__name": "RETRY_S3_BASE_MS",
"__format": "number"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"retryAppConfig": {
"max": 12,
"base": 100
},
"retryS3": {
"max": 12,
"base": 100
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const S3 = require('aws-sdk/clients/s3');
const AppConfig = require('aws-sdk/clients/appconfig');
const config = require('config');

const RETRY_APPCONFIG_MAX = config.get('retryAppConfig.max');
const RETRY_APPCONFIG_BASE_MS = config.get('retryAppConfig.base');
const RETRY_S3_MAX = config.get('retryS3.max');
const RETRY_S3_BASE_MS = config.get('retryS3.base');

async function getContent(contentConfig) {
console.log('getContent', contentConfig);
Expand All @@ -15,7 +21,12 @@ async function getContent(contentConfig) {
throw new Error(`ContentConfig requires either InlineContent or S3Location`);
}

const s3 = new S3();
const s3 = new S3({
maxRetries: RETRY_S3_MAX,
retryDelayOptions: {
base: RETRY_S3_BASE_MS
}
});

const params = {
Bucket: s3Location.BucketName,
Expand All @@ -33,7 +44,12 @@ async function createConfigurationVersion(props) {
console.log('createConfigurationVersion', props);
const content = await getContent(props.ContentConfig);

const appconfig = new AppConfig();
const appconfig = new AppConfig({
maxRetries: RETRY_APPCONFIG_MAX,
retryDelayOptions: {
base: RETRY_APPCONFIG_BASE_MS
}
});
const params = {
ApplicationId: props.ApplicationId,
ConfigurationProfileId: props.ConfigurationProfileId,
Expand All @@ -51,7 +67,12 @@ async function createConfigurationVersion(props) {

async function deleteConfigurationVersion(physicalId, props) {
console.log('deleteConfigurationVersion', props);
const appconfig = new AppConfig();
const appconfig = new AppConfig({
maxRetries: RETRY_APPCONFIG_MAX,
retryDelayOptions: {
base: RETRY_APPCONFIG_BASE_MS
}
});
const params = {
ApplicationId: props.ApplicationId,
ConfigurationProfileId: props.ConfigurationProfileId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"jest": "^26.6.3"
},
"dependencies": {
"aws-sdk": "^2.903.0"
"aws-sdk": "^2.903.0",
"config": "^3.3.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,13 @@ [email protected]:
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=

config@^3.3.8:
version "3.3.8"
resolved "https://registry.yarnpkg.com/config/-/config-3.3.8.tgz#14ef7aef22af25877fdaee696ec64d761feb7be0"
integrity sha512-rFzF6VESOdp7wAXFlB9IOZI4ouL05g3A03v2eRcTHj2JBQaTNJ40zhAUl5wRbWHqLZ+uqp/7OE0BWWtAVgrong==
dependencies:
json5 "^2.2.1"

convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.7.0.tgz#17a2cb882d7f77d3490585e2ce6c524424a3a442"
Expand Down Expand Up @@ -2378,6 +2385,11 @@ json5@^2.1.2:
dependencies:
minimist "^1.2.5"

json5@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c"
integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==

jsprim@^1.2.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2"
Expand Down
24 changes: 22 additions & 2 deletions packages/cdk-appconfig/lib/hosted_configuration_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export interface IHostedConfigurationVersion {
readonly hostedConfigurationVersionArn: string;
}

export interface RetryOptions {
readonly maxRetries: number;
readonly baseDelay: cdk.Duration;
}

export interface HostedConfigurationVersionProps {
readonly application: IApplication;
readonly configurationProfile: IConfigurationProfile;
Expand All @@ -39,6 +44,8 @@ export interface HostedConfigurationVersionProps {
readonly latestVersionNumber?: string;
readonly initOnly?: boolean;
readonly removalPolicy?: cdk.RemovalPolicy;
readonly appConfigRetryOptions?: RetryOptions;
readonly s3RetryOptions?: RetryOptions;
}

export class HostedConfigurationVersion extends cdk.Resource implements IHostedConfigurationVersion {
Expand All @@ -57,13 +64,26 @@ export class HostedConfigurationVersion extends cdk.Resource implements IHostedC

const contentConfig = props.content.bind(this);

const onEventHandler = new lambda.SingletonFunction(this, 'OnEventHandler', {
const onEventHandler = new lambda.Function(this, 'OnEventHandler', {
runtime: lambda.Runtime.NODEJS_14_X,
code: lambda.Code.fromAsset(HANDLER_CODE_PATH),
handler: 'index.onEvent',
uuid: 'c67842de-c9ed-4cbb-906f-3b490af456b8'
// uuid: 'c67842de-c9ed-4cbb-906f-3b490af456b8'
timeout: props.appConfigRetryOptions || props.s3RetryOptions ? cdk.Duration.minutes(15) : undefined
});

if (props.appConfigRetryOptions) {
const { maxRetries, baseDelay } = props.appConfigRetryOptions;
onEventHandler.addEnvironment('RETRY_APPCONFIG_MAX', maxRetries.toString());
onEventHandler.addEnvironment('RETRY_APPCONFIG_BASE_MS', baseDelay.toMilliseconds().toString());
}

if (props.s3RetryOptions) {
const { maxRetries, baseDelay } = props.s3RetryOptions;
onEventHandler.addEnvironment('RETRY_S3_MAX', maxRetries.toString());
onEventHandler.addEnvironment('RETRY_S3_BASE_MS', baseDelay.toMilliseconds().toString());
}

onEventHandler.addToRolePolicy(
new iam.PolicyStatement({
actions: ['appconfig:CreateHostedConfigurationVersion', 'appconfig:DeleteHostedConfigurationVersion'],
Expand Down