Skip to content

Instantly share code, notes, and snippets.

@vaughngit
vaughngit / s3_bucket.py
Created March 1, 2023 21:17
CDK L2 S3 Bucket with Tags applied at bucket level
from aws_cdk import core
from aws_cdk import aws_s3 as s3
class MyS3Bucket(core.Construct):
def __init__(self, scope: core.Construct, id: str):
super().__init__(scope, id)
bucket = s3.Bucket(
self, "MyBucket",
@vaughngit
vaughngit / albfargate.ts
Last active February 28, 2023 22:44
L3 Pattern for ALB Fargate Service
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as ecs_patterns from 'aws-cdk-lib/aws-ecs-patterns';
interface EcsFargateServiceProps {
vpc: ec2.IVpc;
}
export class EcsFargateService extends cdk.Construct {
@vaughngit
vaughngit / L2_vpc.py
Created February 28, 2023 22:17
CDK L2 VPC with L1 overrides in Python
from aws_cdk import core as cdk
from aws_cdk import aws_ec2 as ec2
class MyVpc(cdk.Construct):
def __init__(self, scope: cdk.Construct, id: str, max_azs: int, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
# Create VPC
self.vpc = ec2.Vpc(self, "MyVpc",
@vaughngit
vaughngit / L2vpc.ts
Created February 28, 2023 22:08
CDK L2 VPC Construct Typescript
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
export class MyVpcStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
const vpc = new ec2.Vpc(this, 'MyVpc', {
cidr: '10.0.0.0/16',
maxAzs: 2,
@vaughngit
vaughngit / L1_vpc.py
Last active March 1, 2023 21:13
CDK Lv1 VPC Construct and Tagging in Python
from aws_cdk import core
from aws_cdk import aws_ec2 as ec2
app = core.App()
stack = core.Stack(app, "MyStack")
vpc = ec2.CfnVPC(
stack, "MyVPC",
cidr_block="10.0.0.0/16",
enable_dns_support=True,
@vaughngit
vaughngit / vpc.ts
Created February 28, 2023 21:48
CDK Lv1 VPC Typescript
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
export class MyVpcStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
const vpc = new ec2.CfnVPC(this, 'MyVpc', {
cidrBlock: '10.0.0.0/16',
enableDnsHostnames: true,
@vaughngit
vaughngit / vpc.yaml
Created February 28, 2023 18:49
CloudFormation YAML VPC
---
AWSTemplateFormatVersion: '2010-09-09'
Resources:
MyVpc:
Type: 'AWS::EC2::VPC'
Properties:
CidrBlock: '10.0.0.0/16'
EnableDnsHostnames: true
EnableDnsSupport: true
Tags: