-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
695 additions
and
29 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import { Construct } from 'constructs'; | ||
|
||
export class ExampleA extends cdk.Stack { | ||
public readonly vpc: ec2.IVpc; | ||
public readonly managementSecurityGroup: ec2.ISecurityGroup; | ||
|
||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
this.vpc = new ec2.Vpc(this, 'MyVpc', { | ||
vpcName: 'cdk-day-vpc', | ||
maxAzs: 3, | ||
natGateways: 1, | ||
restrictDefaultSecurityGroup: false, | ||
}); | ||
|
||
this.managementSecurityGroup = new ec2.SecurityGroup(this, 'ManagementSecurityGroup', { | ||
vpc: this.vpc, | ||
}); | ||
} | ||
} |
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,20 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import { Construct } from 'constructs'; | ||
|
||
interface ExampleBProps extends cdk.StackProps { | ||
vpc: ec2.IVpc; | ||
managementSecurityGroup: ec2.ISecurityGroup; | ||
} | ||
|
||
export class ExampleB extends cdk.Stack { | ||
|
||
constructor(scope: Construct, id: string, props: ExampleBProps) { | ||
super(scope, id, props); | ||
|
||
const mySecurityGroup = new ec2.SecurityGroup(this, 'MySecurityGroup', { | ||
vpc: props.vpc, | ||
}); | ||
mySecurityGroup.addIngressRule(props.managementSecurityGroup, ec2.Port.allTraffic()); | ||
} | ||
} |
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,22 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import * as rds from 'aws-cdk-lib/aws-rds'; | ||
import { Construct } from 'constructs'; | ||
|
||
export class StackA extends cdk.Stack { | ||
public readonly db: rds.IDatabaseInstance; | ||
|
||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
const vpc = new ec2.Vpc(this, 'MyVpc', { | ||
vpcName: 'cdk-day-vpc', | ||
}); | ||
|
||
this.db = new rds.DatabaseInstance(this, 'MyDb', { | ||
engine: rds.DatabaseInstanceEngine.POSTGRES, | ||
vpc, | ||
removalPolicy: cdk.RemovalPolicy.DESTROY, | ||
}); | ||
} | ||
} |
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,41 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import * as rds from 'aws-cdk-lib/aws-rds'; | ||
import * as ecs from 'aws-cdk-lib/aws-ecs'; | ||
import * as ecr from 'aws-cdk-lib/aws-ecr'; | ||
import { Construct } from 'constructs'; | ||
|
||
interface StackBProps extends cdk.StackProps { | ||
db: rds.IDatabaseInstance; | ||
} | ||
|
||
export class StackB extends cdk.Stack { | ||
|
||
constructor(scope: Construct, id: string, props: StackBProps) { | ||
super(scope, id, props); | ||
|
||
const cluster = new ecs.Cluster(this, 'MyEcsCluster', { | ||
vpc: ec2.Vpc.fromLookup(this, 'MyVpc', { | ||
vpcName: 'cdk-day-vpc', | ||
}), | ||
}); | ||
|
||
const taskDefinition = new ecs.FargateTaskDefinition(this, 'MyTask'); | ||
|
||
taskDefinition.addContainer('MyApp', { | ||
image: ecs.RepositoryImage.fromEcrRepository( | ||
ecr.Repository.fromRepositoryName(this, 'MyAppEcrRepo', 'my-app'), | ||
'latest', | ||
), | ||
environment: { | ||
DB_ENDPOINT: props.db.dbInstanceEndpointAddress, | ||
}, | ||
}); | ||
|
||
new ecs.FargateService(this, 'MyEcsService', { | ||
cluster, | ||
taskDefinition, | ||
desiredCount: 0, | ||
}); | ||
} | ||
} |
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,21 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as s3 from 'aws-cdk-lib/aws-s3'; | ||
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'; | ||
import * as origins from 'aws-cdk-lib/aws-cloudfront-origins'; | ||
import { Construct } from 'constructs'; | ||
|
||
export class SharedStack extends cdk.Stack { | ||
public readonly distribution: cloudfront.IDistribution; | ||
|
||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
this.distribution = new cloudfront.Distribution(this, 'MyDistribution', { | ||
defaultBehavior: { | ||
origin: new origins.S3Origin( | ||
new s3.Bucket(this, 'MyDefaultBucket'), | ||
), | ||
}, | ||
}); | ||
} | ||
} |
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,21 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as s3 from 'aws-cdk-lib/aws-s3'; | ||
import * as cloudfront from 'aws-cdk-lib/aws-cloudfront'; | ||
import * as origins from 'aws-cdk-lib/aws-cloudfront-origins'; | ||
import { Construct } from 'constructs'; | ||
|
||
interface AppStackProps extends cdk.StackProps { | ||
distribution: cloudfront.IDistribution; | ||
} | ||
|
||
export class AppStack extends cdk.Stack { | ||
|
||
constructor(scope: Construct, id: string, props: AppStackProps) { | ||
super(scope, id, props); | ||
|
||
const appBucket = new s3.Bucket(this, 'MyAppBucket'); | ||
|
||
const distribution = props.distribution as cloudfront.Distribution; | ||
distribution.addBehavior('/my-app/', new origins.S3Origin(appBucket)); | ||
} | ||
} |
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,33 @@ | ||
import * as cdk from 'aws-cdk-lib'; | ||
import * as ecs from 'aws-cdk-lib/aws-ecs'; | ||
import * as ec2 from 'aws-cdk-lib/aws-ec2'; | ||
import * as alb from 'aws-cdk-lib/aws-elasticloadbalancingv2'; | ||
import { Construct } from 'constructs'; | ||
|
||
export class AlbStack extends cdk.Stack { | ||
public readonly ecsCluster: ecs.ICluster; | ||
public readonly albListener: alb.IApplicationListener; | ||
|
||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
|
||
const vpc = ec2.Vpc.fromLookup(this, 'MyVpc', { | ||
vpcName: 'cdk-day-vpc', | ||
}); | ||
|
||
this.ecsCluster = new ecs.Cluster(this, 'MyEcsCluster', { | ||
vpc, | ||
}); | ||
|
||
const loadBalancer = new alb.ApplicationLoadBalancer(this, 'MyAlb', { | ||
vpc, | ||
}); | ||
|
||
this.albListener = loadBalancer.addListener('default', { | ||
port: 80, | ||
defaultAction: alb.ListenerAction.fixedResponse(400, { | ||
messageBody: 'You must use a service path', | ||
}), | ||
}); | ||
} | ||
} |
Oops, something went wrong.