Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPCを追加 #13

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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