@m-yamagishi/aws-cdk-appdp
v0.0.21
Published
AWS CDK Typical application deployment for AWS Fargate, alternative to AWS CDK Pipelines.
Downloads
30
Readme
AWS CDK APPDP
The APIs in this module are experimental and under active development.
AWS CDK Typical application deployment for AWS Fargate, alternative to AWS CDK Pipelines.
This repository structure refers to cdk-pipelines-github.
Usage
Source
declare const githubOwner: string;
declare const githubRepo: string;
declare const targetBranch: string;
const source = AppDpSource.fromGitHub({
owner: githubOwner,
repo: githubRepo,
branch: targetBranch,
oauthToken: SecretValue.secretsManager('github-token'),
});
// FUTURE: fromCodeStarConnection or other repositories
Container Build Definitions
const defaultBuildDefinition = {
directory: '../../',
buildArgs: {
VERSION: 'v2024.09.01.01',
ENV: 'production',
},
};
const appBuildDefinition = new AppDpBuildDefinition(this, 'App', {
...defaultBuildDefinition,
...{
target: 'app',
},
});
const adminBuildDefinition = new AppDpBuildDefinition(this, 'Admin', {
...defaultBuildDefinition,
...{
target: 'admin',
},
});
const cliBuildDefinition = new AppDpBuildDefinition(this, 'CLI', {
...defaultBuildDefinition,
...{
target: 'cli',
},
});
Cluster Configurations
declare const vpc: ec2.Vpc;
const cluster = new AppDpCluster(this, 'AppDpCluster', {
vpc,
});
const appTaskDefinition = new ecs.FargateTaskDefinition(this, 'AppTask', {
cpu: '4096',
memoryLimitMiB: '8192',
executionRole,
taskRole,
});
appTaskDefinition.addContainer('app', {
image: ecs.ContainerImage.fromEcrRepository(appBuildDefinition.repository, source.commitId),
portMappings: [
{
containerPort: 80,
},
],
});
const service = cluster.addHttpService('app', {
taskDefinition: appTaskDefinition,
});
// You can add auto-scaling config to FargateService
const scaling = service.autoScaleTaskCount({
maxCapacity: 100,
});
scaling.scaleOnCpuUtilization('CpuScaling', {
targetUtilizationPercent: 50,
});
const adminTaskDefinition = new ecs.FargateTaskDefinition(this, 'AdminTask', {
cpu: '256',
memoryLimitMiB: '512',
executionRole,
taskRole,
});
adminTaskDefinition.addContainer('admin', {
image: ecs.ContainerImage.fromEcrRepository(adminBuildDefinition.repository, source.commitId),
portMappings: [
{
containerPort: 80,
},
],
});
cluster.addHttpService('admin', {
taskDefinition: adminTaskDefinition,
});
const cliTaskDefinition = new ecs.FargateTaskDefinition(this, 'CLITask', {
cpu: '256',
memoryLimitMiB: '512',
executionRole,
taskRole,
});
cliTaskDefinition.addContainer('cli', {
image: ecs.ContainerImage.fromEcrRepository(cliBuildDefinition.repository, source.commitId),
});
cluster.addNonHttpService('cli', {
taskDefinition: cliTaskDefinition,
});
Pipeline
const pipeline = new AppDpPipeline(this, 'AppDpPipeline', {
source,
buildDefinitions: [
appBuildDefinition,
adminBuildDefinition,
cliBuildDefinition,
],
cluster,
needManualApprove: true, // default: false
});
References
Contributing
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.