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

Implementing PHP as a Custom Runtime on AWS Lambda

Implementing PHP as a Custom Runtime on AWS Lambda

A fifteen minute presentation I gave at the 24th Japan AWS User's Group in Sapporo (on 2019/9/12) describing the requirements and necessary steps to fully implement a custom runtime on AWS Lambda. From building a PHP binary from source using the same AMI/runtime environment as Lambda, to writing a complete event loop handler is presented in detail.

(Note: This presentation is only in Japanese, sorry.)

Michael Tedder

September 12, 2019
Tweet

More Decks by Michael Tedder

Other Decks in Programming

Transcript

  1. $ whoami KBXTVH  ςομʔɹϚΠέϧ ࡀ   ೥Ҏ্ήʔϜ։ൃ ίϯγϡʔϚήʔϜػ


    ϞόΠϧ୺຤1$0DVMVT3JGU73ʣ  Ͱ͖Δ͜ͱΞϓϦ όοΫΤϯυ։ൃήʔϜΤϯδϯ։ൃ
 Πϯϑϥઃܭ%FW0QT $*$% "1*ΠϯςάϨʔγϣϯ  Α͘࢖͏"84αʔϏε-BNCEB"1*(BUFXBZ3%4 %ZOBNP%#(BNF-JGU&$&$34*".  michael.tedder42 !@'BMLFO
  2. ཧ૝ͳ1)1ؔ਺ϋϯυϥʔ KBXTVH  ͳΔ΂͘ରԠϥϯλΠϜͷݴޠͱಉ༷ /PEFKTྫ 
 
 
 
 

    ؔ਺ʹΠϕϯτͱίϯςΩετΦϒδΣΫτ͕
 ύϥϝʔλͰ౉͞Εɺ໭Γ஋ͰϨεϙϯεΛฦ͢
  3. ΧελϜϥϯλΠϜͷϑϩʔ KBXTVH  ॳظԽ " -BNCEBଆͷॳظԽ # ϥϯλΠϜͷॳظԽ  Πϕϯτॲཧʢແݶϧʔϓʣ

    " )551ͰΠϕϯτΛಡΈࠐΉ # ΠϕϯτΛॲཧ͢Δ $ )551ͰϨεϙϯεΛૹΔ ίʔϧυελʔτ ^ ϫʔϜελʔτ ^
  4. ΧελϜϥϯλΠϜͷϑϩʔ KBXTVH  ॳظԽ " -BNCEBଆͷॳظԽ # ϥϯλΠϜͷॳظԽ  Πϕϯτॲཧʢແݶϧʔϓʣ

    " )551ͰΠϕϯτΛಡΈࠐΉ # ΠϕϯτΛॲཧ͢Δ $ )551ͰϨεϙϯεΛૹΔ ίʔϧυελʔτ ^ ϫʔϜελʔτ ^
  5. 1)1Λιʔε͔ΒϏϧυ লུ KBXTVH  ".*࢖ͬͯ&$ΠϯελϯεΛ্ཱͪ͛Δ  "NB[PO-JOVY".*
 BN[OBNJIWNY@HQ  %PDLFSΛར༻ʢ͓͢͢Ίʣ

     '30.BNB[POMJOVY  QIQ NZTRMJ DVSM KTPO NCTUSJOH NIBTIΛDMBOH ͰαΠζ࠷దԽ 0[ ͔͚ͯ.#ͷͭͷ1)1όΠφϦ
  6. ΧελϜϥϯλΠϜͷϑϩʔ KBXTVH  ॳظԽ " -BNCEBଆͷॳظԽ # ϥϯλΠϜͷॳظԽ  Πϕϯτॲཧʢແݶϧʔϓʣ

    " )551ͰΠϕϯτΛಡΈࠐΉ # ΠϕϯτΛॲཧ͢Δ $ )551ͰϨεϙϯεΛૹΔ ίʔϧυελʔτ ^ ϫʔϜελʔτ ^
  7. )551ͰΠϕϯτΛಡΈࠐΉ KBXTVH  1)1ͷDVSM@FYFD ؔ਺౳Λར༻  DVSM@TFUPQU@BSSBZ ͰΦϓγϣϯࢦఆ͢Δ  $63-015@5*.&065


    ωοτϫʔΫλΠϜΞ΢τΛແݶʹ͢Δ ॏཁʂ   $63-015@5$1@/0%&-":USVF
 /BHMFΞϧΰϦζϜΛແޮʹ͢Δ EFMBZ͸ඞཁͳ͍
  8. ΧελϜϥϯλΠϜΛϨΠϠʔʹ KBXTVH  CPPUTUSBQ͕ϧʔτʹ͋ΔΑ͏ʹ[JQΛ࡞੒
 
 
  [JQ͔ΒϨΠϠʔΛ࡞੒ͯ͠-BNCEB΁Ξοϓϩʔυ $ zip

    -v -9 -r -D ../php-7.3.9-runtime.zip * adding: bootstrap (in=66) (out=46) (deflated 30%) adding: php-runtime/bin/php (in=6105792) (out=2471517) (deflated 60%) adding: php-runtime/bootstrap.php (in=6380) (out=2451) (deflated 62%) adding: php-runtime/Context.inc.php (in=1209) (out=628) (deflated 48%) adding: php-runtime/Logger.inc.php (in=1853) (out=784) (deflated 58%) total bytes=6115300, compressed=2475426 -> 60% savings $ aws lambda publish-layer-version --layer-name php-7_3_9-runtime --zip-file fileb://php-7.3.9-runtime.zip
  9. ͢΂ͯΦʔϓϯιʔε KBXTVH  "84-BNCEB1)13VOUJNF-BZFS
 IUUQTHJUMBCDPNDPMEGVTJPOKQBXTMBNCEBQIQSVOUJNF  "844%,GPS1)1-BNCEB-BZFS
 IUUQTHJUMBCDPNDPMEGVTJPOKQBXTTELQIQMBNCEBMBZFS  "NB[PO-JOVY

    DMBOHMMWN%PDLFSJNBHF
 IUUQTIVCEPDLFSDPNSDPMEGVTJPOKQBNB[POMJOVYDMBOH
 IUUQTHJUMBCDPNDPMEGVTJPOKQCVJMEDMBOHMMWN  .*5ϥΠηϯε(JU-BC$*ʹΑΔࣗಈϏϧυ ςετ