Skip to content

Commit

Permalink
[Add]: create a VPC (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutaro-sakamoto authored Oct 4, 2024
1 parent 551567b commit 3b730ae
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
50 changes: 50 additions & 0 deletions infrastructure/lib/constructs/Network/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Construct } from "constructs";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import * as logs from "aws-cdk-lib/aws-logs";
import * as iam from "aws-cdk-lib/aws-iam";

/**
* VPCとVPCエンドポイントに関するリソースを定義する
*/
export class Network extends Construct {
/**
* VPC
*/
public readonly vpc: ec2.Vpc;

constructor(scope: Construct, id: string) {
super(scope, id);

// VPCを作成
this.vpc = new ec2.Vpc(this, "Vpc", {
natGateways: 0,
createInternetGateway: false,
maxAzs: 2,
subnetConfiguration: [
{
cidrMask: 24,
name: "Private",
subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS,
},
],
});

// VPC Flow Logsを作成
const vpcFlowLogGroup = new logs.LogGroup(this, "VpcFlowLogGroup", {
retention: logs.RetentionDays.THREE_DAYS,
});

const vpcFlowLogRole = new iam.Role(this, "VpcFlowLogGroupRole", {
assumedBy: new iam.ServicePrincipal("vpc-flow-logs.amazonaws.com"),
});

new ec2.FlowLog(this, "FlowLog", {
resourceType: ec2.FlowLogResourceType.fromVpc(this.vpc),
trafficType: ec2.FlowLogTrafficType.ALL,
destination: ec2.FlowLogDestination.toCloudWatchLogs(
vpcFlowLogGroup,
vpcFlowLogRole,
),
});
}
}
9 changes: 2 additions & 7 deletions infrastructure/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as cdk from "aws-cdk-lib";
import { Construct } from "constructs";
// import * as sqs from 'aws-cdk-lib/aws-sqs';
import { Network } from "./constructs/Network";

/**
* スタック
Expand All @@ -9,12 +9,7 @@ export class Cobol4JAwsWebStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

// The code that defines your stack goes here

// example resource
// const queue = new sqs.Queue(this, 'ImageBuilder4JQueue', {
// visibilityTimeout: cdk.Duration.seconds(300)
// });
new Network(this, "Network");
}

/**
Expand Down

0 comments on commit 3b730ae

Please sign in to comment.