Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
AWS構成図から CloudFormationとパラメータシートを 自動生成するシステムを作ってみた
Search
つくぼし
June 16, 2024
Technology
12k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AWS構成図から CloudFormationとパラメータシートを 自動生成するシステムを作ってみた
つくぼし
June 16, 2024
More Decks by つくぼし
See All by つくぼし
AI駆動開発におけるハーネスエンジニアリングの勘所
tsukuboshi
1
930
Lambda MicroVMsが分からなすぎたので使い所を1から考えてみた
tsukuboshi
2
720
[モダンアプリ勉強会]今更聞けないGit/GitHub入門
tsukuboshi
0
1.1k
世界の中心でApp Runnerを叫ぶ FINAL
tsukuboshi
0
580
CDKで始めるTypeScript開発のススメ
tsukuboshi
1
2k
Mastraに入門してみた ~AWS CDKを添えて~
tsukuboshi
0
1.6k
Amazon Bedrock GenUハンズオン座学資料 #2 GenU環境でRAGを体験してみよう
tsukuboshi
0
960
Amazon Bedrock GenUハンズオン座学資料 #1 GenU環境で生成AIを体験してみよう
tsukuboshi
0
1.8k
AWSエンジニアに捧ぐLangChainの歩き方
tsukuboshi
5
2.6k
Other Decks in Technology
See All in Technology
[General] 개발자로 해외 기업에서 일하기
skydoves
1
250
AI時代、つくる力を自分たちの手に。 ──電通×KAG、アジャイルとAI駆動開発で挑む開発の変革
yuukiyo
3
450
渡米前の準備を制す!re:Invent 2026徹底準備術 / The Ultimate Preparation Guide for re:Invent 2026
yuj1osm
1
490
基本から分かる!AWSセキュリティ運用の考え方と任せ方
cmusudakeisuke
1
340
AIエージェント統制はAPIから——押さえるべき5つの要素
nagix
0
110
素人でもできた!AIを使った短編小説創作入門
delhi09
PRO
0
280
SLOを阻む不安
sraku2159
0
200
Building Audio Plugin Ecosystem for Android in 2026
atsushieno
1
110
Don't write the architecture only in the prompt.
neohsu
0
290
AIに任せられるFlutterコードベースを作る 〜仕様をコードで表し、ハーネスで守る〜
myohei
1
610
あなたのDartコードは丸見えかもしれない ~reFlutterで暴くFlutterアプリの中身と多層防御~
zozotech
PRO
0
740
Flutter Webを「SDK」として配る — 50以上のゲームを支える埋め込みアーキテクチャ
masayukisuda
0
170
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
41
2.8k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
Embracing the Ebb and Flow
colly
88
5.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Claude Code のすすめ
schroneko
67
230k
The Pragmatic Product Professional
lauravandoore
37
7.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Done Done
chrislema
187
17k
Utilizing Notion as your number one productivity tool
mfonobong
4
630
It's Worth the Effort
3n
188
29k
Tell your own story through comics
letsgokoyo
1
1.1k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.6k
Transcript
AWS構成図から CloudFormationとパラメータシートを 自動生成するシステムを作ってみた 1 2024.6.18 Bedrock Claude Night 2
2 自己紹介 ★ ハンドルネーム ◦ つくぼし ★ 所属 ◦ AWS事業本部コンサルティング部
◦ ソリューションアーキテクト ★ 最近ハマっているAWSサービス ◦ AWS Application Composer ★ SNS/ブログ ◦ X(@tsukuboshi0755) ◦ DevelopersIO(つくぼし)
3 はじめに
4 生成AIではメジャーモデルとして挙げられるClaude • 日本語の文章生成能力が高いと評判 • 多種多様なモデルの中でも最上級のパフォーマンス • 画像認識(Vision)にも対応
5 メジャーなモデルであるClaudeは エンジニアの仕事をどこまで奪えるのか?
6 やってみよう! 自己流のAIクラウドエンジニア を作ってみました
7 AIクラウドエンジニアに任せる事 1. 事前にAWS構成図を作成しpngファイルとして与える 2. その構成図に沿ったCloudFormationテンプレートを出力 3. CloudFormationテンプレートに沿ったパラメータシートを出力
8 AIクラウドエンジニアの解説
9 構成図
10 システムプロンプトの生成 • CFnテンプレートの内容が最大 トークン数以上になる場合でも 回答可能にする処理 • 最大トークン数を取得し、その 80%となるトークン数を計算 •
プロンプト内で指定したトークン 数の80%以上になったら回答を 分割するよう指示 def create_system_prompt() -> str: max_token = int(os.environ["MAX_TOKEN"]) eighty_percent_token = int(max_token / 10 * 8) system_prompt = f""" \n回答は以下の条件全てを満たすようにしてください: \n- 必ず回答で出力するCloudFormationテンプレート(yaml形式)の先頭 は"```yaml"、末尾は"```"とする。 \n- 必要に応じて補足を付与したい場合は、回答で出力するCloudFormationテン プレート内に#を付けてコメントとして記載する。 \n- もし回答が{eighty_percent_token}トークンを超えたら、{max_token} トークンに達するまでに一旦回答を分割し、ユーザーが「続き」と入力したら続きの 回答を作成する。 """ logger.info("System Prompt: %s", system_prompt) return system_prompt
11 ユーザープロンプトの生成 • 存在しないリソースタイプを用い てテンプレートが生成されないよ う回答させる処理 • CFn ListTypes APIを用いて、
AWS::から始まるリソースタイプ リストを取得 • プロンプト内で取得したリソース タイプ以外のものを使用しない よう指示 # 一部省略 def generate_yaml(system_prompt: str, tmp_image_path: str) -> Any: while True: response = cfn.list_types( Visibility="PUBLIC", **({"NextToken": next_token} if next_token else {}) ) type_summaries.extend(response["TypeSummaries"]) next_token = response.get("NextToken") if not next_token: break type_list = [ summary["TypeName"] for summary in type_summaries if summary["TypeName"].startswith("AWS::") ] first_generate_text = f""" (中略) \n- 以下の<リソースタイプリスト>に存在しないリソースタイプは、回答で出力 するCloudFormationテンプレートのリソースタイプとして使用してはいけない。 \n\n<リソースタイプリスト> \n{type_list} """
12 YAMLフォーマットと会話履歴によるファイル連結 • Claudeで生成された回答の 内、YAML内容のみを抜き出し て正しく連結する処理 • Claudeが生成した回答から YAMLファイルの箇所のみを抽 出し、改行を入れて連結
• 次のYAML量が最初の80%を超 える場合のみ、Claudeへの質 問・抽出・連結を繰り返す # 一部省略 for yaml_count in range(max_yaml_count): next_res_message = request_bedrock(model_id, messages, next_content_text, system_prompt) next_row_content = next_res_message["content"][0]["text"] logger.info(f"Next Response {yaml_count}: %s", next_row_content) next_yaml_content = format_yaml(next_row_content) yaml_content += "\n" + next_yaml_content next_yaml_length = len(next_yaml_content) if next_yaml_length > eighty_percent_first_yaml_length: messages.append(next_res_message) else: break def format_yaml(row_content: str) -> str: match = re.search(r"```yaml\n(.*?)\n```", row_content, re.DOTALL) if match: response_text = match.group(1) return response_text else: return ""
13 CFnテンプレートとしてのレビューとバリデーション • バリデーション結果が正常とな るまで、テンプレートをClaudeで レビューさせる処理 • CFn ValidateTemplate APIを用
いて、テンプレートにエラーがな いか確認 • エラーがある場合のみエラー メッセージを含めて、Claudeに 繰り返しレビューさせる # 一部省略 def lambda_handler(event: Dict[Any, Any], context: Any) -> Dict[str, Any]: for review_count in range(max_review_count): logger.info(f"Validation Status: {status}") if status == "normally": break else: reviewed_yaml = review_yaml( system_prompt, tmp_image_path, target_yaml, cfn_res ) status, cfn_res = cfn_validate(reviewed_yaml) target_yaml = reviewed_yaml def review_yaml(system_prompt: str, tmp_image_path: str, yaml_content: str, cfn_err: Any) -> Any: first_review_text = f""" \nもしエラーメッセージが何かしら追加で提示されている場合は、エラーを解消 できるように更新したテンプレートを全て出力してください。 \n\n<CloudFormationテンプレート> \n{yaml_content} \n\n<エラーメッセージ> \n{cfn_err} """
14 サンプルCSVを元にしたパラメータシート生成 • 事前に与えたCSVファイルとテ ンプレートを元にパラメータシー トを生成する処理 • CSVファイルには生成したい表 形式のサンプル項目を事前に記 載
• プロンプト内で取得したCSVファ イルの形式を参考にするよう指 示 # 一部省略 def request_bedrock(tmp_template_path: str) -> Any: with open(prompt_path, "rt") as csv_file: complement_prompt = csv_file.read() content_text = f""" \n\nHuman: \n<質問> \n提示されたサンプルパラメータシートの形式を参考にしながら、提示された CloudFormationテンプレートを反映するパラメータシート(CSV形式)を作成してく ださい。 \nパラメータシートには、以下の条件全てを満たすようにしてください: \n- 必要なすべてのリソースとそれらの設定を含める \n- テンプレートに基づきリソース間の依存関係や参照を適切に記載する \n\n<サンプルパラメータシート> ```csv {complement_prompt} ``` \n\n<CloudFormationテンプレート> \n```yaml \n{yaml_content} \n``` """
15 AIクラウドエンジニアの紹介デモ
16 入力する構成図の例
17 生成されたテンプレート(Application Composerより)
18 生成されたパラメータシート
19 最後に
20 Claudeは仕事を代替できるのか?(個人的感想) • 現時点では全てが代替されるという事はなさそう ◦ 個人的には70-80%くらいの完成度ならできそう、一方で90%以上の正確さを求め るのは正直厳しい印象 ◦ 与えられるインプット(構成図)も完璧ではないので、何かとブレは生じがち •
Claudeの特性をアプリ側の処理で上手く補助すると、求めるものにより近 づける事ができる ◦ 動的なプロンプトの生成 ◦ 会話履歴を用いたテンプレートのフォーマットと連結 ◦ エラーを考慮したレビューとバリデーションの繰り返し ◦ サンプルファイルを元にしたパラメータシート生成
21 まとめ AIクラウドエンジニアに仕事を任せて サボれるようになりたい!
22 宣伝 6/28(金)〜7/31(水)で社外イベントやります 生成AI関連のオンライン登壇ももりだくさん!
23