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

陽の目を見ないCloudformationのマイナー機能に光を当てる

 陽の目を見ないCloudformationのマイナー機能に光を当てる

2016/07/22 Infrastructure as Code勉強会

chao2suke

July 22, 2016
Tweet

More Decks by chao2suke

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ w ਗ਼໺ɹ߶࢙ ͤʔͷʣ w "84$POTVMUJOH෦ॴଐʢҰԠޒףʣ w *P5ؔ܎Λ୲౰ w ࢠҭͯத

    ࡀ˂  w ͲΜͳʹࣾ಺͕"OTJCMFҰ৭ʹͳͬͯ΋$IFGͷࣄΛ৴ͯ͡Δ w ͏ͪͷ໨ͷલ͕ϙέεϙοτʹ ৽ೖࣾһ Ίͦࢠ (޿ใ݉ਓࣄʣ
  2. • Cloud-Init͸AmazonLinuxʹೖ͍ͬͯΔॳظઃఆπʔϧ • ݩʑUbuntuͰ࡞ΒΕͨ΋ͷ • AMIΛ࡞ͬͯ͠·͏ͱΞϓϦͷόʔδϣϯ͕ݻఆ͞Εͯ࢖͍ʹ͍͘ɺΈ͍ͨͳ࣌ʹศ ར • Πϯελϯεͷ“ىಈ࣌”ʹ[userdata]಺ʹॻ͔Ε͍ͯΔεΫϦϓτΛݺͼग़͢(Init.dʹ ొ࿥͞Ε͍ͯΔ)

    • Cloud-Init͸มߋʹ͸cloud.cfgͷमਖ਼͕ඞཁ=>CFnΛॻ͖׵͑ͯ࠶࣮ߦ͕Ͱ͖ͳ͍ • cfn-init͸σϑΥϧτͰ͸૸Βͳ͍ • userdata಺ʹىಈεΫϦϓτΛॻ͍ͯॳΊͯ૸Δ cfn-initͱCloud-initͷҧ͍
  3. cfn-init "UserData" : { "Fn::Base64" : { "Fn::Join" : ["",

    [ "<script>\n", "cfn-init.exe -v -s ", { "Ref" : "AWS::StackId" }, " -r instance1 ", " --region ", { "Ref" : "AWS::Region" }, "\n", "</script>" ]]}},
  4. cfn-init "Metadata" : { "AWS::CloudFormation::Init" : { "config" : {

    "files" : { "c:\\cfn\\cfn-hup.conf" : { "content" : { "Fn::Join" : ["", [ "[main]\n", "stack=", { "Ref" : "AWS::StackId" }, "\n", "region=", { "Ref" : "AWS::Region" }, "\n" ]]} }, "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf" : { …………. }, "commands" : { "1-run-timezone" : { "command" : { "Fn::Join" : [ "", [ "powershell.exe -Command \"tzutil /s 'Tokyo Standard Time_dstoff'\"" ]]}, "waitAfterCompletion" : "0" }, "2-rename-computername" : { "command" : { "Fn::Join" : [ "", [ "powershell.exe -Command \"Rename-Computer -NewName instance1 -restart\"" ]]}, "waitAfterCompletion" : "forever" },
  5. cfn-init "Metadata" : { "AWS::CloudFormation::Init" : { "config" : {

    "files" : { "c:\\cfn\\cfn-hup.conf" : { "content" : { "Fn::Join" : ["", [ "[main]\n", "stack=", { "Ref" : "AWS::StackId" }, "\n", "region=", { "Ref" : "AWS::Region" }, "\n" ]]} }, "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf" : { …………. }, "commands" : { "1-run-timezone" : { "command" : { "Fn::Join" : [ "", [ "powershell.exe -Command \"tzutil /s 'Tokyo Standard Time_dstoff'\"" ]]}, "waitAfterCompletion" : "0" }, "2-rename-computername" : { "command" : { "Fn::Join" : [ "", [ "powershell.exe -Command \"Rename-Computer -NewName instance1 -restart\"" ]]}, "waitAfterCompletion" : "forever" },
  6. configSets "AWS::CloudFormation::Init" : { "configSets" : { "ascending" : [

    "config1" , "config2" ], "descending" : [ "config2" , "config1" ] }, "config1" : { "commands" : { "test" : { "command" : "echo \"$CFNTEST\" > test.txt", "env" : { "CFNTEST" : "I come from config1." }, "cwd" : "~" } } }, "config2" : { "commands" : { "test" : { "command" : "echo \"$CFNTEST\" > test.txt", "env" : { "CFNTEST" : "I come from config2" }, "cwd" : "~" } } } }
  7. cfn-hup "Metadata" : { "AWS::CloudFormation::Init" : { "config" : {

    "files" : { "c:\\cfn\\cfn-hup.conf" : { "content" : { "Fn::Join" : ["", [ "[main]\n", "stack=", { "Ref" : "AWS::StackId" }, "\n", "region=", { "Ref" : "AWS::Region" }, "\n" ]]} }, "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf" : { "content": { "Fn::Join" : ["", [ "[cfn-auto-reloader-hook]\n", "triggers=post.update\n", "path=Resources.instance1.Metadata.AWS::CloudFormation::Init \n", "action=cfn-init.exe -v -s ", { "Ref" : "AWS::StackId" }, " -r instance1", " --region ", { "Ref" : "AWS::Region" }, "\n" ]]} }, "commands" : { ……….
  8. cfn-hup "Metadata" : { "AWS::CloudFormation::Init" : { "config" : {

    "files" : { ………….. }, "commands" : { ……….. }, "services" : { "windows" : { "cfn-hup" : { "enabled" : "true", "ensureRunning" : "true", "files" : ["c:\\cfn\\cfn-hup.conf", "c:\\cfn\\hooks.d\\cfn-auto-reloader.conf"] } } }
  9. cfn-hup "Metadata" : { "AWS::CloudFormation::Init" : { "config" : {

    "files" : { ………….. }, "commands" : { ……….. "99-signal-success" : { "command" : { "Fn::Join" : ["", [ "cfn-signal.exe -e 0 \"", { "Fn::Base64" : { "Ref" : "InstanceWaitHandle" } },"\"" ]] }, "InstanceWaitCondition" : { "Type" : "AWS::CloudFormation::WaitCondition", "DependsOn" : "Instance1", "Properties" : { "Handle" : {"Ref" : "InstanceWaitHandle"}, "Timeout" : "1500" } }, "InstanceWaitHandle" : { "Type" : "AWS::CloudFormation::WaitConditionHandle" }