Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWS Transform CustomでIaCコードを自由自在に変換しよう

Avatar for k-kun k-kun
April 28, 2026

AWS Transform CustomでIaCコードを自由自在に変換しよう

2026年4月28日のAWS JawsユーザーズグループAI/ML支部のGenerative AI LT大会での登壇時に使用した資料です。

Avatar for k-kun

k-kun

April 28, 2026

More Decks by k-kun

Other Decks in Technology

Transcript

  1. JAWS -UG AI/ML #37 AWS Generative AI/ML LT 大会 AWS

    Transform Custom でIaC コード (CDK 、 CloudFormation 、 Terraform) を自由自在に変換しよう Kiyomasa Miyamoto IBM Japan 28 th April in 2026
  2. Agenda 1. 自己紹介 2. IaC コード変えたいと思ったことはありませんか? 3. AWS Transform Custom

    概要 4. AWS Transform Custom による IaC コード変換検証 1. 検証内容 2. Transform Custom CLI 実行フロー 3. CloudFormation から CDKへの変換結果 4. CloudFormation から Terraform への変換結果 5. 今回の検証で得られた知見 5. まとめ
  3. 1. 自己紹介 ⚫ 氏名:宮本 清正 ⚫ 経歴:大学院修士 修了後、新卒入社。 (大学院時代はシステム制御 (AI

    の前身)を研究。 ) • 勤続25 年。 主にメインフレーム (IBM Z) の運用自動化領域の技術支援を実施中。 • 社内AI 推進活動実施中 • 社内AWS コミュニティーにおける AWS エンジニア育成活動実施中 (3 年) ⚫ 好きな IT 技術: クラウド 、 AI 、 Linux 、 IaC (Ansible,Terraform etc)、ネットワーク ⚫ 好きな AWS サービス: CloudFormation 、 Kiro 、 Systems Manager 、 VPC Lattice など。 ⚫ AWS 受賞歴 ⚫ 2024 -2025 Japan AWS All Certifications Engineers ⚫ 2025 AWS Community Builders (Global 表彰) ※Network & Content Delivery 領域にて選出 PMI 認定資格(PMP) G検定
  4. 2. IaC コード変えたいと思ったことはありませんか? ⚫ IaC を実践されている方、こんな悩みをもったことはないでしょうか。 ⚫ これまで CloudFormation を使ってきたけど、

    CDKでも IaC ができるようになりたい。 ➢ 今の時代、 AI エージェントで CDKのコードは手軽に作成することはできる。 ➢ ただし、プログラミング経験が乏しいと、作成された CDKのコードレビューが困難。。 ➢ 1から CDK入門するのも、それはそれで結構な時間を要するし、途中で挫折するかもしれない。 ➢ でも、自分が作成した CloudFormation のコードを CDKに変換できれば、それを使って勉強した方が CDKの理解が早くなるのでは。 ⚫ CloudFormation から、コマンド一発でプロビジョニング可能な Terraform に移行したいなー。 ➢ CloudFormation はYAML だけど、 Terraform はHCL。これを地道に書き換えるのは結構面倒。 このお悩み、後述の「 AWS Transform Custom 」を使えば解決できます!
  5. 3. AWS Transform Custom 概要 ⚫ AWS Transform が提供している機能の 1つで、ソフトウェア、コード、ライブラリー、フレームワーク等の

    モダナイズを、エージェンティック AI を使って自動変換できるようにするサービス https://aws.amazon.com/jp/transform/custom/ ⚫ エージェントには、以下を含む AWS のマネージド変換機能が提供されている。 ⚫ プログラミング言語 (Java 、 Node.js 、 Python) のバージョンアップグレード ⚫ AWS SDK(Java 、 Node.js 、 Python) のマイグレーション ⚫ コード解析、 Java の性能分析など ※IaC を変換してくれる AWS のマネージド変換機能は現状提供されていないが、 Transform Custom の AI エージェントと自然言語で会話することで、後述の CloudFormation →CDK、 Terraform への変換を 行うことが可能。
  6. 3. AWS Transform Custom 概要 ⚫ AWS Transform の中で、 Transform

    Custom は唯一ウェブコンソールに加えて、専用の CLI が用意されている。 https://docs.aws.amazon.com/transform/latest/userguide/custom -get -started.html ⚫ Linux と mac OS では利用できるが、 Windows はサポート対象外。 (Windows の場合は別途WSL が必要) ⚫ 前提ソフトウェアとして、 Node.js (V20 以降)と Gitが必要。 ⚫ Transform Custom が稼働できるのは、バージニア北部 (us -east -1) 、フランクフルト (eu -central -1) のみ。 ※AWS CLI 等で、デフォルトのリージョンを国内リージョンにされている場合はご注意ください。 ⚫ コンソールから「 atx 」と実行すると、 AI エージェントとインタラクティブなやり取りを開始できる。
  7. Resouce Configuration 4. AWS Transform Custom による IaC コード変換検証 1.

    検証内容 ⚫ 変換元のCloudFormation コードは、下記の AWS 構成をプロビジョニングするものとする。 ⚫ Consumer VPC 上のEC2 インスタンスが、サービスネットワークエンドポイントから、サービスネットワークを 経由し、 Resource VPC 内のRDSインスタンスへのアクセスを行う。 ⚫ CloudFormation コードの内訳は下記の通り。 (コードの詳細は GitHub リポジトリ を参照。 ) ⚫ CreateRG -NetWork.yaml :右側の Resource VPC 周りを作成 ⚫ CreateCS -ServiceNetwork.yaml :左側の CosumerVPC 周りと中央の VPC Lattice Service Network を作成 ⚫ CreateCS -PrivateEC2.yaml :左側の CosumerVPC で稼働するプライベート EC2 インスタンスを作成 ⚫ Create_SSMEndpoint.yaml :プライベート EC2 インスタンス接続用の SSMエンドポイントを作成 Consumer VPC Private subnet Instances Service Network Endpoint SSM Endpoint Session Manager Client Resource VPC ap-northeast-1a ap-northeast-1a ap-northeast-1c Private subnet Private subnet Amazon VPC Lattice Service Network Resouce Gateway
  8. 4. AWS Transform Custom による IaC コード変換検証 2. Transform Custom

    CLI 実行フロー ⚫ Transform Custom CLI を起動後、下記のようなプロンプトを入力。 (プロンプトはサンプル ) ⚫ CDKへの変換ケース ⚫ Terraform への変換ケース ⚫ 現在は、 IaC をサポートしている AWS 提供Transformation リストが無いため、下記のような質問をしてくる。 ※AI エージェントからの問いかけの為、毎回同じ質問とは限らない。 (Transform CLI のバージョンによる違いもありそう。 ) >Please transform from CloudFormation Code to AWS CDK for Python. To create a solid transformation definition, it would be useful to know : 1. What types of CloudFormation resources are most commonly used in your templates (e.g., EC2, S3, Lambda, VPC, IAM, RDS)? 2. Are your CloudFormation templates written in JSON, YAML, or a mix of both? And do they make heavy use of intrinsic functions (like Fn::If, Fn::Sub, Conditions, Mappings)? If you have any migration guides, documentation, or example CloudFormation templates and their desired CDK equivalents, feel free to share file paths and I can use those to build a more precise transformation definition. You can always add these later if you don't have them handy right now. >Please transform from CloudFormation Code to Terraform Code.
  9. 4. AWS Transform Custom による IaC コード変換検証 2. Transform Custom

    CLI 実行フロー ⚫ 前頁のAI エージェントからの質問に、下記のように回答。 (回答はサンプル ) ⚫ AI エージェントがユーザーのホームディレクトリ内にある「 .aws /atx /custom 」ディレクトリ配下に作業日時を含む ディレクトリを作成後、 transformation_definition.md( 今回の要件整理)を作成。ユーザーに確認を求めてくる。 ⚫ 元のCloudFormation コードは実行の順序性があるため、その点を忘れずに AI エージェントに伝える。 ⚫ AI エージェントが summaries.md( 作業概要)、 plan.json (変換作業計画)を作成する。その際、検証用に必要な コマンドは何が良いかを聞いてくるので、今回は以下のように回答。 (ユーザー自身で好きなものを指示する。 ) ⚫ CDKへの変換検証: cdk synth コマンド ⚫ Terraform への変換検証: terraform init コマンド、及び、 terraform validate コマンド >These AWS resources(EC2,VPC,RDS,VPC Lattice,SSM ) are most commomly used in my templates. And my CloudFormation templates is written in YAML and use of intrinsic functions. >My CloudFormation Codes are run on the following sequence (CreateRG -NetWork.yaml -> CreateCS - ServicceNetWork.yaml -> CreateCS -PrivateEC2.yaml -> Create_SSMEndpoint.yaml). These codes are located in /home/testuser/transform -cdk/aws -service -network -foundation .
  10. 4. AWS Transform Custom による IaC コード変換検証 2. Transform Custom

    CLI 実行フロー ⚫ 以降は、 AI エージェント側で、元の CloudFormation コード (計4個)を下記のディレクトリ内に格納し、適宜参照 しながらコード変換処理を実施していく。 格納先: ~/. aws /atx /custom/xxx/artifacts/ tp-staging/ document_references ⚫ 各々のコードに対する変換処理の中では、下記が行われている。 ➢ コードの構文エラーチェック (ユーザーが指定したコマンドを実行 ) ➢ AI エージェント自身でテストケースを作成し、モジュールの依存関係や、変数のインポート情報等に 抜けが無いかをチェック ⚫ 全てのコード変換処理完了後、 validation_summary.md( 変換作業レポート )を作成し、ユーザーに確認を求めてくる。 ⚫ ユーザーは、 validation_summary.md の内容確認、変換されたコードの中身を実際に確認し、必要に応じて AI エージェントに追加の改修を指示する。 (コードの稼働確認はユーザーにて実施。 )
  11. 4. AWS Transform Custom による IaC コード変換検証 3. CloudFormation から

    CDKへの変換結果 ⚫ 以下は生成された CDKのメインプログラム (app.py) 。必要な CDKコードの詳細は GitHub リポジトリ を参照。 #!/usr/bin/env python3 """AWS CDK application entry point. Instantiates four stacks in deployment order: 1. RG-Network (VPC, Subnets, RDS, VPC Lattice Resource Gateway/Configuration) 2. CS -ServiceNetwork (Consumer VPC, NAT GW, VPC Lattice Service Network) 3. CS -PrivateEC2 (Private EC2 instance) 4. SSM -Endpoint (SSM VPC Endpoints) ""“ import aws_cdk as cdk from stacks import ( CsPrivateEc2Stack, CsServiceNetworkStack , RgNetworkStack , SsmEndpointStack , ) app = cdk.App () # Stack 1: RG -Network rg_network_stack = RgNetworkStack ( app, "RG-Network", ) # Stack 2: CS -ServiceNetwork (depends on Stack 1) cs_service_network_stack = CsServiceNetworkStack ( app, "CS-ServiceNetwork ", resource_config_id =rg_network_stack.resource_config_id , ) # Stack 3: CS -PrivateEC2 (depends on Stack 2) cs_private_ec2_stack = CsPrivateEc2Stack( app, "CS-PrivateEC2", private_subnet_02_id=cs_service_network_stack.private_subnet_02 _id, private_subnet_sec_grp_02_id=cs_service_network_stack.private_s ubnet_sec_grp_02_id, ) # Stack 4: SSM -Endpoint (depends on Stack 2) ssm_endpoint_stack = SsmEndpointStack ( app, "SSM-Endpoint", vpc_id =cs_service_network_stack.vpc_id , vpc_cidr_block =cs_service_network_stack.vpc_cidr_block , private_subnet_02_id=cs_service_network_stack.private_subnet_02 _id, ) app.synth ()
  12. 4. AWS Transform Custom による IaC コード変換検証 3. CloudFormation から

    CDKへの変換結果 ⚫ 生成された CDKコードの稼働確認を実施。問題なし。 ⚫ CDKのブートストラップを実施 [rheluser@localhost temp1]$ cdk bootstrap aws://xxxxxxxxxxx/ap -northeast -1 Bootstrapping environment aws ://xxxxxxxxxxx /ap-northeast -1... Trusted accounts for deployment: (none) Trusted accounts for lookup: (none) Using default execution policy of ' arn:aws:iam :: aws:policy /AdministratorAccess '. Pass ' --cloudformation -execution -policies' to customize. CDKToolkit : creating CloudFormation changeset... Environment aws://xxxxxxxxxxxxxx/ap -northeast -1 bootstrapped. ⚫ CDKのデプロイを実施 [rheluser@localhost temp1]$ cdk deploy --all Synthesis time: 6.38s Proceeding anyway. RG-Network: start: Building RG -Network Template RG-Network: success: Built RG -Network Template CS-ServiceNetwork : start: Building CS -ServiceNetwork Template CS-ServiceNetwork : success: Built CS -ServiceNetwork Template CS-PrivateEC2: start: Building CS -PrivateEC2 Template CS-PrivateEC2: success: Built CS -PrivateEC2 Template SSM-Endpoint: start: Building SSM -Endpoint Template SSM-Endpoint: success: Built SSM -Endpoint Template
  13. 4. AWS Transform Custom による IaC コード変換検証 3. CloudFormation から

    CDKへの変換結果 ⚫ CDKのデプロイ (続き ) RG-Network: creating CloudFormation changeset... RG-Network Deployment time: 601.07s CS-ServiceNetwork : start: Publishing CS -ServiceNetwork Template CS-ServiceNetwork : success: Published CS -ServiceNetwork Template CS-ServiceNetwork Deployment time: 144.24s CS-PrivateEC2 Deployment time: 48.53s Stack SSM -Endpoint SSM-Endpoint Deployment time: 85.25s
  14. 4. AWS Transform Custom による IaC コード変換検証 3. CloudFormation から

    CDKへの変換結果 ⚫ CDKのデプロイまで完了後、プライベート EC2 にSSM セッションマネージャーで接続し、サービスネットワーク エンドポイントを使って、リモート VPCにある RDSインスタンスに接続できることを確認。結果、問題なし。 [rheluser@localhost temp1]$ aws ssm start -session --target i -0bf2972b15ebc64e6 Starting session with SessionId : ProdUser -skxutfsxfx38dtq5bftbnqhzpy $ bash ssm -user@ip -20 -0-1-153:/var/snap/amazon -ssm -agent/9881$ cd ssm -user@ip -20 -0-1-153:~$ which psql /usr /bin/psql ssm -user@ip -20 -0-1-153:~$ psql --host=rds -pgsql.cfkatwfqxj4d.ap -northeast -1.rds.amazonaws.com --port=5432 --username= postgres --password – -dbname =db01 Password: psql (16.13 (Ubuntu 16.13 -0ubuntu0.24.04.1), server 16.6) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off) Type "help" for help. db01=>
  15. 4. AWS Transform Custom による IaC コード変換検証 4. CloudFormation から

    Terraform への変換結果 ⚫ 色々修正依頼はしつつ、最終的に生成させたルートの main.tf ファイル。コードの詳細は GitHub リポジトリ を参照。 # Root module orchestrator # Modules are wired in deployment sequence: # 1. rg_network (no dependencies) # 2. cs_service_network (depends on rg_network ) # 3. cs_private_ec2 (depends on cs_service_network ) # 4. ssm_endpoint (depends on cs_service_network ) module " rg_network " { source = "./modules/ rg-network" } module " cs_service_network " { source = "./modules/cs -service -network" resource_config_id = module.rg_network.resource_config_id depends_on = [module.rg_network ] } module "cs_private_ec2" { source = "./modules/cs-private -ec2" private_subnet_id = module.cs_service_network.private_subnet_02_id private_security_group_id = module.cs_service_network.private_subnet_sec_grp_02_id depends_on = [module.cs_service_network ] } module " ssm_endpoint " { source = "./modules/ ssm -endpoint" vpc_id = module.cs_service_network.vpc_id vpc_cidr_block = module.cs_service_network.vpc_cidr_block private_subnet_id = module.cs_service_network.private_subnet_02_id depends_on = [module.cs_service_network ] }
  16. 4. AWS Transform Custom による IaC コード変換検証 4. CloudFormation から

    Terraform への変換結果 ⚫ 生成した Terraform コードの稼働確認を実施。いずれも問題なし。 ⚫ terraform apply まで完了後、プライベート EC2 にSSMセッションマネージャーで接続し、サービスネットワーク エンドポイントを使って、リモート VPCにある RDSインスタンスに接続できることを確認。結果、問題なし。 [rheluser@localhost service -network]$ aws ssm start -session --target i -0b176c314181d7ac8 Starting session with SessionId : ProdUser -iudxn74gusyxdasevy5dkf5pye $ bash ssm -user@ip -20 -0-1-224:~$ psql --host=rds -pgsql.cfkatwfqxj4d.ap -northeast -1.rds.amazonaws.com --port=5432 --username= postgres --password --dbname =db01 Password: psql (16.13 (Ubuntu 16.13 -0ubuntu0.24.04.1), server 16.6) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off) Type "help" for help. db01=> STEP1. モジュールの取り込み ・ terraform init コマンドを実行 [rheluser@localhost service -network] $ terraform init Initializing the backend... Initializing modules... - cs_private_ec2 in modules/cs -private -ec2 - cs_service_network in modules/cs -service -network - rg_network in modules/ rg-network - ssm_endpoint in modules/ ssm -endpoint Initializing provider plugins... Terraform has been successfully initialized! STEP2. 内容確認 ・ terraform plan コマンドを実行 [rheluser@localhost service -network] $ terraform plan Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create : : Plan: 33 to add, 0 to change, 0 to destroy. STEP3. プロビジョニングの実施 ・ terraform apply コマンドを実行 [rheluser@localhost service -network] $ terraform apply Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create : : Apply complete! Resources: 33 added, 0 changed, 0 destroyed.
  17. 4. AWS Transform Custom による IaC コード変換検証 5. 今回の検証で得られた知見 コード変換ケース

    良かった点 人間のレビューが重要と感じた点 CloudFormation から CDKへの変換 ・ CloudFormation で使用していた論理リソース 名をそのまま CDKでも引き継いでくれたこと。 ・今回は CDK for Python を利用したが、比較的可 読性の良いコードを作成してくれたこと。 ・特に生成されたコードを修正することなく、 目的となる構成をプロビジョニングできたので、 今回は気になった点はなし。 CloudFormation ⇒Terraform への変換 ・複数ソースを module 形式に変換して、 1つの main.tf から実行できるようにしてくれたこと。 ・生成されたコードから、 module 間、 module 内部各々における依存関係を指定する 「 depends_on 」ステートメントの指定が完全 に抜け落ちてしまった。 ・ CloudFormation コードでは、 NAT ゲートウェ イはリージョナル型のものを作成する記述をし ていたが、 Terraform への変換が適切に行われな かった。その為、 2,3 回位修正させた。 ※EIP の指定は不要なのに設定してしまう、接続 タイプを public から private に変えてしまう等。 ・ CloudFormation では、セキュリティーグルー プを作成すると、デフォルトでアウトバウンド 通信が許可(コンソールからの作成時も同様 )され るが、 Terraform では明示的に指定しないと設定 されない (Terraform の仕様)ので、 AI に変換させ るのであれば、プロンプトで指示するなどが必 要になる。
  18. 5. まとめ ⚫ 今回は、 AWS Transform Custom を利用して、既存の CloudFormation コードから

    CDK、 Terraform への コード変換を行い、そこで得られた知見を紹介した。 ⚫ 現状、 AWS Transform Custom のマネージドサービスの中に、今回のような IaC ツールの変換をサポートしている ものはないが、自然言語によるプロンプト入力のみで、比較的容易に変換が可能。 ⚫ CDKが純正のAWS サービスであるのに対し、 Terraform はOSSということもあり、 Terraform への 変換を行う際には、より人間のレビューが必要になると感じた。 ※前頁に記載した Terraform への変換における知見に関しては、 Terraform Custom CLI V1.7.1 で試した際に経験した内容。 しかし、最新の V1.9.0 で再度試しても結果は同じだったので、今後も考慮は必要。 ⚫ AWS Transform Custom CLI は、定期的にバージョンアップされるため、コード変換を行う際には なるべく最新のバージョンを利用することを推奨。 (現時点では、 V1.9.0 が最新。 )