0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS CDK v1(TypeScript)でVPC作成時のAZを指定する

Last updated at Posted at 2022-03-22

概要

AWS CDKでVPCと同時にサブネットを作成するとき、AZが自動で選択されてしまう
旧AZ(apne1-az3)1ではできないことがいくつかあるため、AZを指定したい

実行環境

:~ $ cdk version
1.148.0 (build 69a50f1)

解決方法

availabilityZones()を、指定したいAZ名を返すようにオーバーライドする

こんな感じ

import * as cdk from '@aws-cdk/core'
import * as ec2 from '@aws-cdk/aws-ec2'

export class MyStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new ec2.Vpc(this, 'VPC', {
      cidr: '10.0.0.0/16',
      subnetConfiguration: [
        {
          cidrMask: 24,
          name: 'subnet-test',
          subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
        },
      ]
    })
  }

  get availabilityZones(): string[] {
    return ['ap-northeast-1a', 'ap-northeast-1c'];
  }
}

  1. AZ名ではなくAZ IDで書いている。AZ IDについてはこちらを参照

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?