Share
Embed
AWS環境でIaCを使い始めて運用するためのメリットデメリットと注意点
mokonist
June 26, 2020
Transcript
46 slides
-
2 ⾃⼰紹介 もこ クラスメソッド株式会社 AWS事業本部 コンサルティング部ソリューションアーキテクト 2020 APN AWS Top
Engineers 現職: Terraform/CDKでAWS環境の構築 前職: ECサイトのSREっぽい事 好き: アプリとインフラの中間、TypeScript 好きなAWSサービス: ECS/Amplify/CDK Twitter/GitHub: mokocm -
22 Terraform // vpc resource "aws_vpc" "vpc" { cidr_block =
"10.0.0.0/16" } // igw resource "aws_internet_gateway" "igw" { vpc_id = aws_vpc.vpc.id } // subnet (a) resource "aws_subnet" "subnet_a" { cidr_block = "10.0.0.0/24" vpc_id = aws_vpc.vpc.id availability_zone = "ap-northeast-1a" } // subnet (c) resource "aws_subnet" "subnet_c" { cidr_block = "10.0.0.1/24" vpc_id = aws_vpc.vpc.id availability_zone = "ap-northeast-1c" } -
23 Terraform // Route Table(0.0.0.0/0 igw) resource "aws_route_table" "public" {
vpc_id = aws_vpc.vpc.id route { cidr_block = "0.0.0.0/0" gateway_id = aws_internet_gateway.igw.id } } // RouteTableにAssociation resource "aws_route_table_association” "subnet_a" { route_table_id = aws_route_table.public.id subnet_id = aws_subnet.subnet_a.id } resource "aws_route_table_association" "subnet_c" { route_table_id = aws_route_table.public.id subnet_id = aws_subnet.subnet_c.id } -
26 CDK import { Stack, Construct, StackProps, Duration } from
'@aws-cdk/core'; import { Vpc } from '@aws-cdk/aws-ec2’ export class SlackTranslateBotStack extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, props); const vpc = new Vpc(this, 'TheVPC', { cidr: "10.0.0.0/16" }) } } -
28 CDK https://dev.classmethod.jp/articles/aws-cdk-serverless-develop/ CDK + Lambdaで開発がめちゃめちゃ捗る︕ constructor(scope: Construct, id: string,props?:StackProps)
{ super(scope, id, props); const lambda = new NodejsFunction(this, 'lambda', { entry: 'lambda/app.ts’, handler: 'handler’, runtime: Runtime.NODEJS_12_X, timeout: Duration.minutes(5) }); const api = new LambdaRestApi(this, 'api', { handler: lambda }); } -
29 その他 | Serverless ・AWS SAM(Serverless Application Model) ・CLIとCloudFormationの拡張、デプロイが楽 ・実態はCloudFormationのTransform
・Serverless Framework ・ymlでサーバーレス環境を簡単に設定 -
31 IaCの運⽤⽅法 ・Gitで管理して、開発者がトピックブランチからmasterブランチに Pull Requestを出し、CIで現環境との差分、コードのレビューを受ける ・もちろんmasterブランチは保護して、承認なく直接Push出来ないように ・masterブランチにマージされたら環境に適⽤する ・Terraformの場合はS3にtfstateを保存する terraform {
backend "s3" { bucket = "bucket-name-here" key = "terraform.tfstate" encrypt = ture region = "ap-northeast-1" } } -
43 IaCの運⽤⽅法 Q. それって「Immutable Infrastructure」では︖ A. はい。 // あくまで個⼈的感想であり理想論で、今⽇⼀番伝えたかった事 開発者はインフラを積極的に世話したいとは思わないし
アプリケーション開発に集中したい せっかくクラウドにリフトするなら、インフラを極⼒世話しない環境に しませんか︖