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
CloudFormationで登場したForEachをちゃんと理解してみる
Search
Yuki_Kurono
August 25, 2023
Technology
910
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CloudFormationで登場したForEachをちゃんと理解してみる
フレッシュメンLT #0 夏祭り
https://connpass.com/event/285559/
Yuki_Kurono
August 25, 2023
More Decks by Yuki_Kurono
See All by Yuki_Kurono
Terraform(IaC)と実環境の乖離どうしていますか?
yuki_kurono
0
49
今年のre:inventから学ぶこと
yuki_kurono
0
110
re_invent 2023事前勉強会
yuki_kurono
0
100
CloudFormationの運用が 辛くならない方法を本気で考えてみた
yuki_kurono
0
380
Turnstileのウィジェット モードとは何者か
yuki_kurono
0
730
CodeGuru Security ってなんだ?
yuki_kurono
0
1.2k
えるしってるか CloudFrontはWAFがあっても カスタムエラーレスポンスを返せる
yuki_kurono
0
450
Cloudflare初心者がIaCから基本構成を学んでみた
yuki_kurono
1
660
Terraformのnull_resource ってなに?aws cli が実行できるらしい
yuki_kurono
1
1.6k
Other Decks in Technology
See All in Technology
AIで社員の自主発信に広報目線を組み込む
_mossann_t
0
140
Argo CDとAtlantisで実現するインフラ管理のセルフサービス化──小規模SREチームで支えるプラットフォーム
cassius7
0
150
C#未経験の僕がAIに読めるコードを書かせるまで
maguroalternative
0
300
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
16
120k
What the customer really needed
kawaguti
PRO
3
230
認知負荷を吸収し、プロダクトをまたぐPR Preview基盤の設計事例
taiki45
2
310
Why Agent Cost Needs Observability
nttcom
0
160
2026-09-18 gotanda.sre Terraformで複数環境作ったり、複数Stateに分割したりそれとTerragrunt / Terraform multi envs and multi states
masasuzu
4
730
AWS DevOps Agent スキルをつかいこなそう / Master AWS DevOps Agent Skills
kinunori
1
490
手を動かして実感する、Kiro が変える開発体験
inariku
0
320
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
12k
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
4
1.3k
Featured
See All Featured
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
680
Rails Girls Zürich Keynote
gr2m
96
14k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Agile that works and the tools we love
rasmusluckow
331
22k
The Cost Of JavaScript in 2023
addyosmani
55
10k
HDC tutorial
michielstock
2
910
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
390
Statistics for Hackers
jakevdp
799
230k
The Curious Case for Waylosing
cassininazir
1
540
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
370
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
290
Transcript
CloudFormationで登場した ForEachをちゃんと理解してみる Yuki Kurono 2023/8/25 #フレッシュメンLT
自己紹介 #フレッシュメンLT 黒野 雄稀 Yuki Kurono アイレット株式会社 新卒4年目 普段はインフラ設計・構築や運用構築に従事 2022/2023
Japan AWS All Certifications Engineers 2023 Japan AWS Top Engineers AWS Community Builders(Cloud Operations)
CloudFormationとは AWSで提供されるInfrastructure as Code(IaC)サービス IaC = コードしてインフラを管理しようぜ! テンプレートと呼ばれるファイルにコードを記述する 記述方法はJson or
YAMLを使うことができる AWSTemplateFormatVersion: '2010-09-09' Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 #フレッシュメンLT
CloudFormationならではの良さもある。 • 環境構築が要らない • YAML,Jsonでの統一された書き方 • AWSサービスとの組み合わせの相性も良い • 対応しているAWSリソースの多さ •
etc… CloudFormation使ってる? #フレッシュメンLT
CloudFormationならではの良さもある。 • 環境構築が要らない • YAML,Jsonでの統一された書き方 • AWSサービスとの組み合わせの相性も良い • 対応しているAWSリソースの多さ •
etc… CloudFormation使ってる? #フレッシュメンLT NO
これまでのCloudFormationでの構築、運用は辛いと思うことが多かった。 • 冗長的なコードの記述 ←これが結構大きかった。 • etc… CloudFormationなんで使わないの? #フレッシュメンLT
様々なプログラミング言語でも使える様なループ処理が行える機能です。 これを使うことで冗長なコードの定義が不要となりました。 ForEachってなんだ? #フレッシュメンLT Parameters: VPCList: Type: List<String> Default: VPC01,VPC02,VPC03
Resources: Fn::ForEach::VPCListLoop: - VPCNames - !Ref VPCList - ${VPCNames}: Type: AWS::EC2::VPC Properties: CidrBlock: "192.168.0.0/16" Tags: - Key: Name Value: !Ref VPCNames Resources: VPC01: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 VPC02: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 VPC03: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 ==
ForEachは単体で使うと1つの値しかループさせることができない。 例えばサブネット名とか。 →でもサブネットを作るにはCIDR、Azの名前など色々な値を可変させたいです よね? ForEachイケてると思う使い方 #フレッシュメンLT Fn::ForEach::SubnetListLoop: - SubnetNames -
!Ref SubnetList - ${SubnetNames}: Type: AWS::EC2::Subnet Properties: VpcId: !Ref VPC CidrBlock: : "192.168.0.0/16" AvailabilityZone: "ap-northeast-1a" Tags: - Key: Name Value: !Ref SubnetNames
AWSTemplateFormatVersion: 2010-09-09 Transform: "AWS::LanguageExtensions" Parameters: SubnetList: Type: List<String> Default: SubnetPuba,SubnetWeba,SubnetDBa
Mappings: SubnetMappings: SubnetPuba: cidrBlock: "192.168.1.0/24" az: ap-northeast-1a nameTags: subnet-pub-a SubnetWeba: cidrBlock: "192.168.2.0/24" az: ap-northeast-1a nameTags: subnet-web-a SubnetDBa: cidrBlock: "192.168.3.0/24" az: ap-northeast-1a nameTags: subnet-db-a Resources: Fn::ForEach::SubnetListLoop: - SubnetNames - !Ref SubnetList - ${SubnetNames}: Type: AWS::EC2::Subnet Properties: VpcId: !Ref VPC CidrBlock: !FindInMap - SubnetMappings - !Ref SubnetNames - cidrBlock AvailabilityZone: !FindInMap - SubnetMappings - !Ref SubnetNames - az Tags: - Key: Name Value: !FindInMap - SubnetMappings - !Ref SubnetNames - nameTags Mappings Foreach 複数の値をMappingで渡して 参照する
まとめ • これまで冗長なコードを記載する必要があったものが解決されかなり 便利になるアップデートだと思います! • ForEachと併せてMappingを使うと複数の値(パラメータ値)をループさ せることができるので、これを使うことでよりコードを短縮して書く ことができるのでオススメ • ForEach内で使用できる組み込み関数やクオータなどの制約事項につい
ても注意が必要となりますので、より詳しく知りたい方は公式ページ を参考にするとよいかと思います。 ◦ https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-foreach.html #フレッシュメンLT