-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
551567b
commit 3b730ae
Showing
2 changed files
with
52 additions
and
7 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
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, | ||
), | ||
}); | ||
} | ||
} |
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