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
14 changes: 13 additions & 1 deletion packages/cdk-appconfig-examples/bin/cdk-examples.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import { HostedConfigurationStack, LambdaExtensionStack } from '../lib';
import {
HostedConfigurationStack,
LambdaExtensionStack,
S3ConfigurationStack,
SsmDocumentConfigurationStack,
SsmParameterConfigurationStack
} from '../lib';

const app = new cdk.App();

new HostedConfigurationStack(app, 'AppConfigExample-HostedConfiguration');

new LambdaExtensionStack(app, 'AppConfigExample-LambdaExtension');

new S3ConfigurationStack(app, 'AppConfigExample-S3Configuration');

new SsmDocumentConfigurationStack(app, 'AppConfigExample-SsmDocumentConfiguration');

new SsmParameterConfigurationStack(app, 'AppConfigExample-SsmParameterConfiguration');
3 changes: 3 additions & 0 deletions packages/cdk-appconfig-examples/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"message": "Hello, World!"
}
45 changes: 45 additions & 0 deletions packages/cdk-appconfig-examples/lib/codefresh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
steps:
configure_environment:
title: Configure environment
type: freestyle
image: alpine
commands:
- >
case "${{CF_BRANCH}}" in
master)
cf_export ENV=prod
cf_export AWS_REGIONS=us-east-1,eu-west-1,ap-southeast-1
cf_export AWS_PROFILE=vmx-vcas-prod
;;
develop)
cf_export ENV=dev
cf_export AWS_REGIONS=us-east-1,eu-west-1
cf_export AWS_PROFILE=vmx-vcas-dev
;;
*)
cf_export ENV=sandbox
cf_export AWS_REGIONS=us-east-1
cf_export AWS_PROFILE=vmx-vcas-sandbox
;;
esac
build_image:
type: build
...
deploy_infrastructure:
type: freestyle
commands:
- yarn cdk deploy "MultiDRM" --profile ${{AWS_PROFILE}}
when:
condition:
any:
envIsDev: '"${{ENV}}" == "dev"'
envIsProd: '"${{ENV}}" == "prod"'
deploy_code:
type: freestyle
commands:
- yarn create-deployment --stack-name MultiDRM --profile ${{AWS_PROFILE}}
when:
condition:
any:
envIsDev: '"${{ENV}}" == "dev"'
envIsProd: '"${{ENV}}" == "prod"'
3 changes: 3 additions & 0 deletions packages/cdk-appconfig-examples/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from './hosted-configuration-stack';
export * from './lambda-extension-stack';
export * from './s3-configuration-stack';
export * from './ssm-document-configuration-stack';
export * from './ssm-parameter-configuration-stack';
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class LambdaExtensionStack extends cdk.Stack {
name: 'demo'
});

const configuration = new appconfig.HostedConfigurationProfile(this, 'Profile', {
const configuration = new appconfig.HostedConfigurationProfile(this, 'Configuration', {
application,
name: 'ExclamationPoints',
validators: [
Expand Down
48 changes: 48 additions & 0 deletions packages/cdk-appconfig-examples/lib/s3-configuration-stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as path from 'path';

import * as cdk from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';
import * as s3Deploy from '@aws-cdk/aws-s3-deployment';
import * as appconfig from '@cuperman/cdk-appconfig';

export class S3ConfigurationStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const configBucket = new s3.Bucket(this, 'ConfigBucket', {
versioned: true
});

const configDeployment = new s3Deploy.BucketDeployment(this, 'ConfigDeployment', {
sources: [s3Deploy.Source.asset(path.join(__dirname, '../config'))],
destinationBucket: configBucket
});

const application = new appconfig.Application(this, 'App');

new appconfig.Environment(this, 'Environment', {
application
});

const configuration = new appconfig.S3ConfigurationProfile(this, 'Configuration', {
application,
validators: [
appconfig.JsonSchemaValidator.fromInline(
`{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"message": { "type": "string" }
},
"required": ["message"],
"additionalProperties": true
}`
)
],
s3Bucket: configBucket,
s3ObjectKey: 'config.json'
});

configuration.node.addDependency(configDeployment);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as cdk from '@aws-cdk/core';
import * as ssm from '@aws-cdk/aws-ssm';
import * as appconfig from '@cuperman/cdk-appconfig';

export class SsmDocumentConfigurationStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const schema = new ssm.CfnDocument(this, 'Schema', {
name: 'MySchema',
documentType: 'ApplicationConfigurationSchema',
documentFormat: 'JSON',
content: {
$schema: 'http://json-schema.org/draft-04/schema#',
type: 'object',
properties: {
message: { type: 'string' },
description: { type: 'string ' },
version: { type: 'integer' },
foo: { type: 'string' }
},
required: ['message'],
additionalProperties: false
},
versionName: 'Foo'
});

// const doc = new ssm.CfnDocument(this, 'Doc', {
// documentType: 'ApplicationConfiguration',
// documentFormat: 'JSON',
// content: {
// message: 'Hello, World!'
// },
// requires: [
// {
// name: schema.ref,
// version: '2'
// }
// ]
// });

// doc.addDependsOn(schema);

// const application = new appconfig.Application(this, 'App');

// new appconfig.Environment(this, 'Environment', {
// application
// });

// new appconfig.SsmDocumentConfigurationProfile(this, 'Configuration', {
// application,
// ssmDocument: doc
// });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as cdk from '@aws-cdk/core';
import * as ssm from '@aws-cdk/aws-ssm';
import * as appconfig from '@cuperman/cdk-appconfig';

export class SsmParameterConfigurationStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const param = new ssm.StringParameter(this, 'Param', {
type: ssm.ParameterType.STRING,
stringValue: JSON.stringify({
message: 'Hello, World!'
})
});

const application = new appconfig.Application(this, 'App');

new appconfig.Environment(this, 'Environment', {
application
});

new appconfig.SsmParameterConfigurationProfile(this, 'Configuration', {
application,
validators: [
appconfig.JsonSchemaValidator.fromInline(
`{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"message": { "type": "string" }
},
"required": ["message"],
"additionalProperties": true
}`
)
],
ssmParameter: param
});
}
}
11 changes: 7 additions & 4 deletions packages/cdk-appconfig-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@
"prepublishOnly": "run-s test"
},
"devDependencies": {
"@aws-cdk/assert": "1.110.1",
"@aws-cdk/assert": "1.112.0",
"@types/jest": "^26.0.10",
"@types/node": "10.17.27",
"aws-cdk": "1.110.1",
"aws-cdk": "1.112.0",
"jest": "^26.4.2",
"npm-run-all": "^4.1.5",
"ts-jest": "^26.2.0",
"ts-node": "^9.0.0",
"typescript": "~3.9.7"
},
"dependencies": {
"@aws-cdk/aws-lambda": "^1.110.1",
"@aws-cdk/core": "1.110.1",
"@aws-cdk/aws-lambda": "^1.112.0",
"@aws-cdk/aws-s3": "^1.112.0",
"@aws-cdk/aws-s3-deployment": "^1.112.0",
"@aws-cdk/aws-ssm": "^1.112.0",
"@aws-cdk/core": "1.112.0",
"@cuperman/cdk-appconfig": "^0.7.0",
"@cuperman/cdk-appconfig-handler-hello-world": "^0.7.0",
"source-map-support": "^0.5.16"
Expand Down
Loading