1
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?

【AWS CDK】いっけね!間違えてバージニア北部にデプロイしちゃった...(備忘録)

Posted at

備忘録になります。

なぜ間違えた?

AWS学習中にCDKで定義したVPCやサブネットをデプロイした際に、シンプルにリージョン周りを正しく確認していなかったためです...。

具体的には以下のような状態でした。

  • aws configureでアクセスキーなどを入力する際にリージョンをデフォルトにしたまま。

  • bin/~.tsに明示的にリージョンを記述していなかった。

bin/~.ts
import * as cdk from "aws-cdk-lib";
import { AwsTestStack } from "../lib/aws-test-stack";

const app = new cdk.App();
new AwsTestStack(app, "AwsTestStack", {
});

解決策

1. デフォルトのリージョンを変更

aws configure set regionでリージョンを設定

aws configure set region ap-northeast-1 # 東京リージョンをセット

bin/~.tsリージョンを記述

bin/~.ts
import * as cdk from "aws-cdk-lib";
import { AwsTestStack } from "../lib/aws-test-stack";

const app = new cdk.App();
new AwsTestStack(app, "AwsTestStack", {
   env: { region: 'ap-northeast-1' },  // 東京リージョンを明示的に指定
});

2. 間違えてデプロイしたリージョンのリソースを削除

# cdk destroy --region [削除対象のリージョン]
cdk destroy --region us-east-1 # バージニア北部のリソースを削除

安全に削除するために

削除対象の確認

# cdk diff --region [削除対象のリージョン]
cdk diff --region us-east-1

スタック名を指定して削除

# cdk destroy [スタック名] --region [削除対象のリージョン]
cdk destroy AwsTestStack --region us-east-1

3. 再デプロイ

# cdk bootstrap --region [デプロイ対象のリージョン]
cdk bootstrap --region ap-northeast-1
# cdk deploy --region [デプロイ対象のリージョン]
cdk deploy --region ap-northeast-1

最後にAWS Console上より、Cloud Formationメニューへ遷移し、
正しいリージョンにデプロイされていることを確認する。

1
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
1
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?