Slide 1

Slide 1 text

Wo rd P re s s g o e s m o re C l o u d ! - I n f r a s t r u c t u re a s C o d e Ͱ Wo rd P re s s Λ Α Γ ศ ར ʹ J A W S D AY S 2 0 1 7 LT

Slide 2

Slide 2 text

· ͱ Ί • CloudFormationͰߏங͢ΔΞϓϦͷߏ੒ΛίʔυԽ͠Α͏ • EC2 Systems ManagerͰίϚϯυ࣮ߦ΍ΞϓϦͷঢ়ଶΛίʔυԽ͠Α͏ • Ͳͬͪ΋ແྉͳͷʹهࣄগͳ͍͔ΒΈΜͳ΋ͬͱ࢖ͬͯهࣄॻ͜͏ʂ

Slide 3

Slide 3 text

Wo rd P re s s ࢖ ͬͯ ͳ ͍ ਓ ͸ E C 2 Ͱ ಈ ͔ ͯ͠ Δ Ξ ϓ Ϧ ʹ ஔ ͖ ׵ ͑ͯ ߟ ͑ Α ͏

Slide 4

Slide 4 text

H i d e t a k a O k a m o t o • AMIMOTO / Shifter • WordBenchKyoto • WordCamp Kyoto 2017

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

I f y o u c re a t e Wo rd P re s s S e r v e r • AWSίϯιʔϧΛ։͘ • EC2ͰΠϯελϯεΛىಈ • WordPressΛϓϩϏδϣϯ • WordPressηοτΞοϓ

Slide 9

Slide 9 text

؅ ཧ ͢ Δ α ʔόʔ ͕ ૿ ͑ͯ͘Δ ͱ ɾ ɾ ɾ • Πϯελϯεϩʔϧ෇͚๨Εͨɾɾɾ • Πϯελϯεফ࣌͢ʹηΩϡϦςΟάϧʔϓফ͠๨ΕͯΔɾɾɾ • UserDataͷίϐϖϛεͬͯϓϩϏδϣϯ͕ࣦഊͨ͠ɾɾɾ • खॱΛ·ͱΊΔͷΊΜͲ͍͘͞ɾɾɾ

Slide 10

Slide 10 text

AW S C l o u d F o r m a t i o n

Slide 11

Slide 11 text

C l o u d F o r m a t i o n Λ ࢖ ͑ ͹ • SG΍Πϯελϯεϩʔϧ΋JSON / YAMLͰఆٛͰ͖Δ • ফ͠๨Ε΍ରԠ࿙Ε͕͓͖ͳ͘ͳΔ • RDS΍EFS , CloudFrontͳͲͱͷ࿈ܞ΋ίʔυԽͰ͖Δ • ʮ͜ͷखॱͰߏஙͯ͠ʯͱ͍͏खॱॻ͕ཁΒͳ͘ͳΔ

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

t e r r a f o r m ͡ Ό μϝ ͳ ͷ ʁ • AWS SDK͔Βૢ࡞Ͱ͖ΔͷͰɺCloudFormation೿Ͱ͢ • ͱ͸͍͑terraformͰ͔͠࡞Εͳ͍Ϧιʔε΋͋Δ(SESͳͲ) • terraformͰCloudFormationͷػೳΛΧόʔ͢Δ • MarketPlaceʹϓϩμΫτͱͯ͠ܝࡌͰ͖Δͷ΋CloudFormation

Slide 14

Slide 14 text

A M I M O T O Ͱ ͷ ར ༻ ྫ

Slide 15

Slide 15 text

Wo rd P re s s ͷ Π ϯ ϑ ϥ ͸ ό Ϧ Τʔ γ ϣ ϯ ͕ ଟ ͍ • ͜ͷҊ݅͸EC2ͱRDS • ͬͪ͜͸CloudFrontͱELB΋ඞཁ • ͋ͷҊ݅ը૾૿͖͔͑ͯͨΒS3௥Ճ͠Α͏͔ͳ • AutoScale͍ͨ͠ͷ͕ग़͖͔ͯͨΒEFSͰϚ΢ϯτ͠Α͏ →ຖճϦιʔεΛίϐϖͯ͠ςϯϓϨʔτ࡞Δͷ͕ۤߦʹɾɾɾ

Slide 16

Slide 16 text

$Stack_Type = 'autoscale' AWSTemplateFormatVersion "2010-09-09" Description (<<-EOS).undent WordPress powered by JINKEI (AutoScaling HVM) EOS Resources do if $Stack_Type == 'autoscale' then _include 'include/iam/instance_profile.rb' else _include 'include/iam/for_stack_001.rb' end end Mappings do _include "include/mapping/ami_as.rb" _include "include/mapping/amimoto_config.rb" end k u m o g a t a & k u m o g a t a 2 • Codenize.tools ͷ̍ͭ • Ruby DSLͰCloudFormation͕ॻ͚Δ • ϦιʔεผʹϑΝΠϧΛ࡞ͬͯ include͢Ε͹࠶ར༻Ͱ͖Δ • if΍ม਺ɾ_includeͰߏ੒ΧελϜ͕ ؆୯ʹ

Slide 17

Slide 17 text

A f t e r s e t u p Wo rd P re s s • WordPressͷίΞɾϓϥάΠϯͷόʔδϣϯΛ֬ೝ͍ͨ͠ • PHP΍OSͷόʔδϣϯ΋ݟ͓͔ͯͳ͍ͱ • ͲͷΠϯελϯεʹͲͷυϝΠϯ͕ೖ͍ͬͯΔ͔΋֬ೝ͍ͨ͠ • Let’s Encryptͷূ໌ॻߋ৽ࣗಈԽ΋͠ͳ͚Ε͹ɾɾɾ → ӡ༻ϚχϡΞϧɾखॱॻ͕ͲΜͲΜ૿͍͑ͯ͘

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

E C 2 S y s t e m s M a n a g e r • ΠϯϕϯτϦͰΠϯελϯε৘ใΛίϯιʔϧ͔ΒҰ๬Ͱ͖Δ • Run commandͰ೚ҙͷ৘ใΛΠϯϕϯτϦͤ͞Δ͜ͱ͕Մೳ • State ManagerͰΞοϓσʔτίϚϯυΛఆظ࣮ߦ͢Δ͜ͱ΋ʂ • ConfigͰมߋཤྺΛτϥοΩϯάͰ͖ΔͷͰ؂ࢹʹ΋࢖͑Δ

Slide 20

Slide 20 text

E C 2 S y s t e m s M a n a g e r f o r Wo rd P re s s • ؅ཧ͍ͯ͠ΔαʔόʔʹΠϯετʔϧ͞ΕͨWPαΠτΛΠϯϕϯτϦ • ֤WordPress಺ͷϓϥάΠϯ໊ͱόʔδϣϯΛΠϯϕϯτϦ • AWS ConfigΛ࢖ͬͯʮউखʹຊ൪Ξοϓσʔτ΍Β͔ͨ࣌͠ظʯͷಛఆ • WP-CLI + Run commandͰWPૢ࡞͸͍͍ͩͨͳΜͰ΋Ͱ͖Δ

Slide 21

Slide 21 text

E C 2 S y s t e m s M a n a g e r ࢖ ͬͯ Έͯ ײ ͡ ͨ ͜ ͱ • Run command࢖͏͚ͩͩͱɺ݁ہίϚϯυखॱॻ͕ඞཁʹͳΔ • DocumentԽ͠Α͏ͱ͢ΔͱɺJSONͱͷಆ͍͕͸͡·Δ

Slide 22

Slide 22 text

{ "schemaVersion":"2.0", "description":"Run a script", "mainSteps":[ { "action":"aws:runShellScript", "name":"runShellScript", "inputs":{ "commands":"aws ssm put-inventory -- instance-id "ID" --items '[{"CaptureTime": "2016-08-22T10:01:01Z", "TypeName": "Custom:RackInfo", "Content":[{"RackLocation": "Bay B/Row C/Rack D/Shelf E"}], "SchemaVersion": "1.0"}]'" } }, Π ϯϕ ϯ τ Ϧ ί Ϛ ϯ υ υ Ω ϡ ϝ ϯ τ υΩϡϝϯτ༻ͷதͷJSON಺ʹ ΠϯϕϯτϦͷͨΊͷJSONΛͶ͡ࠐΉ ↓ ݟ௨͕͠ѱͯ͘؅ཧͮ͠Β͍

Slide 23

Slide 23 text

schemaVersion: "1.2" description: "Example Documents by CFN" runtimeConfig: aws:runShellScript: properties: - id: 0.aws:runShellScript runCommand: - INSTANCEID=$(/usr/bin/curl -s http:// 169.254.169.254/latest/meta-data/instance-id) - WPVERSION=$(sudo -u ec2-user /usr/ local/bin/wp core version --path=/var/www/html/) - ITEMS=$(jo -a $(jo CaptureTime=$(date +%Y-%m-%dT%H:%M:%SZ) TypeName=Custom:DefaultWPVersion Content=$ (jo -a $(jo wp_version=${WPVERSION})) SchemaVersion=\"1.0\") | sed 's/\\"//g') - aws ssm put-inventory --instance-id "$ {INSTANCEID}" --items "$(echo ${ITEMS})" A W S : : S S M : : D o c u m e n t • Run Command༻υΩϡϝϯτͷCFN • CloudFormation͔ͩΒYAMLͰ͔͚Δ • SSMͰ࣮ߦ͢ΔίϚϯυ΋ίʔυԽ

Slide 24

Slide 24 text

$ rezept help put_inventory Usage: rezept put_inventory -c, --content=key:value -i, --instance-id=INSTANCE_ID -n, -- name=NAME Options: -n, --name=NAME # The name of the inventory type -i, --instance-id=INSTANCE_ID # EC2 Instance ID -c, --content=key:value # Parameters for the document [--schema-version=SCHEMA_VERSION] # The schema version for the <ޙུ> A tool to manage EC2 Systems Manager (SSM) Documents with programmable DSL. R E Z E P T

Slide 25

Slide 25 text

E C 2 S y s t e m s M a n a g e r ࢖ ͬͯ Έͯ ײ ͡ ͨ ͜ ͱ • CloudFormation΍RezeptͰ؅ཧ͢Ε͹ӡ༻͸ָʹͰ͖ͦ͏ • AWSͷνϡʔτϦΞϧ͕਌੾ͳͷͰɺ؆୯ʹ͸͡ΊΔ͜ͱ͕Ͱ͖Δ • ͨͩ͠೔ຊޠͷهࣄ͕΄ͱΜͲແ͍ͷͰԠ༻ܥ͸ख୳ΓʹͳΓ͕ͪ • ʮແྉʯͰʮศརʯͳͷʹͳͥʁ

Slide 26

Slide 26 text

– ษ ڧ ձ ओ ࠵ ͯ͠ Δ ਓ ͨ ͪ “ؼͬͯϒϩάΛॻ͘·Ͱ͕ษڧձͰ͢”

Slide 27

Slide 27 text

C l o u d F o r m a t i o n ͱ E C 2 S y s t e m s M a n a g e r ͷ ه ࣄ Λ Έ Μ ͳ ΋ ͬ ͱ ॻ ͜͏ ʂ

Slide 28

Slide 28 text

Wo rd P re s s ωλ ͳ Β Wo rd C a m p K y o t o 2 0 1 7 ΁ ʂ h t t p s : / / 2 0 1 7 . k y o t o . w o rd c a m p . o rg /