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

CloudFormationアンチパターンのお話

 CloudFormationアンチパターンのお話

Yuki_Kurono

August 24, 2022
Tweet

More Decks by Yuki_Kurono

Other Decks in Programming

Transcript

  1. 自己紹介 名前 黒野 雄稀 AWS歴 
 ・約3年
 ・2022 APN ALL

    AWS Certifications Engineer
 所属 アイレット株式会社 普段の業務
 ・基幹系インフラ構築
 ・システム運用構築

  2. ExportとImportValue "Resources" : { "WebServerInstance": { "Type": "AWS::EC2::Instance", "Properties": {

    "InstanceType" : "t2.micro", "NetworkInterfaces" : [{ "SubnetId" : { "Fn::ImportValue" : "WebSubnet" }, "GroupSet" : [ { "Fn::ImportValue" : "WebSG" } } ], Outputs: WebSubnet01: Description: Web Public Subnet Value: !Ref WebSubnet Export: Name: "WebSubnet" WebSG01: Description: Web Security Group Value: !Ref WebSG Export: Name: "WebSG" WebApp.yaml Network.yaml Export、ImportValueを使用することで、スタック(テンプレートファイル)間で値の受け渡しが 可能。
 任意の名前を使用してExportできます。

  3. ExportとImportValue Outputs: WebSubnet: Description: Web Public Subnet Value: !Ref WebSubnet

    Export: Name: !Sub "${AWS::StackName}-WebSubnet" WebSG: Description: Web Security Group Value: !Ref WebSG Export: Name: !Sub "${AWS::StackName}-WebSG" PrivateSubnet: Description: Private Subnet Value: !Ref PrivateSubnet Export: Name: !Sub "${AWS::StackName}-PrivateSubnet" PrivateSG: Description: Private Security Group Value: !Ref WebPrivateSG Export: Name: !Sub "${AWS::StackName}-PrivateSG" DatabaseSubnet: Description: Database Subnet Value: !Ref DatabaseSubnet Export: Name: !Sub "${AWS::StackName}-DatabaseSubnet" DatabaseSG: Description: Database Security Group Value: !Ref DatabaseSG Export: Name: !Sub "${AWS::StackName}-DatabaseSG" Web02Subnet: Description: Web Public Subnet02 Value: !Ref Web02Subnet Export: Name: !Sub "${AWS::StackName}-Web02Subnet" Web02SG: Description: Web02 Security Group Value: !Ref WebSG Export: Name: !Sub "${AWS::StackName}-Web02SG" Private02Subnet: Description: Private02 Subnet Value: !Ref Private02Subnet Export: Name: !Sub "${AWS::StackName}-Private02Subnet" Private02SG: Description: Private02 Security Group Value: !Ref Private02SG Export: Name: !Sub "${AWS::StackName}-Private02SG" Database02Subnet: Description: Database02 Subnet Value: !Ref Database02Subnet Export: Name: !Sub "${AWS::StackName}-Database02Subnet" Database02SG: Description: Database02 Security Group Value: !Ref Database02SG Export: Name: !Sub "${AWS::StackName}-Database02SG" Web03Subnet: Description: Web Public Subnet03 Value: !Ref Web03Subnet Export: Name: !Sub "${AWS::StackName}-Web03Subnet" Web03SG: Description: Web03 Security Group Value: !Ref WebSG Export: Name: !Sub "${AWS::StackName}-Web03SG" Private03Subnet: Description: Private03 Subnet Value: !Ref Private03Subnet Export: Name: !Sub "${AWS::StackName}-Private03Subnet" Private03SG: Description: Private03 Security Group Value: !Ref Private03SG Export: Name: !Sub "${AWS::StackName}-Private03SG" Database03Subnet: Description: Database03 Subnet Value: !Ref Database03Subnet Export: Name: !Sub "${AWS::StackName}-Database03Subnet" Database03SG: Description: Database03 Security Group Value: !Ref Database03SG Export: Name: !Sub "${AWS::StackName}-Database03SG" Network.yaml Export名どれ。。。? AWSリソース数が膨大な場合には、Export名を管理するのがほ ぼ不可能になる。。・

  4. まとめ • まずはCFn始めてみよう。
 ◦ その他のIaCに比べ、学習コストは低いと思います!
 ◦ 実際に使ってみて分かることの方が多いと思う。
 
 • Count

    Macroというマクロ機能を使うとFor文を実現できるみたいなのでまた遊んでみよ うと思います。
 
 • 機能追加されて、使いやすくなることを期待してます!!

  5. 参考 - Qiita - https://qiita.com/kurono/items/b3362e16a3a396b9b2a7 - 公式ドキュメント - https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html

    https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html