AWS CloudFormation — 101

Mart — Tanathip Viriya
1 min readJun 12, 2020

การสร้าง Infrastructure ไม่ได้ทําได้เพียงแค่กดบนหน้า GUI อย่างเดียว เรายังสามารถเขียน Infrastructure เป็น Yaml / JSON file ทิ้งไว้ก่อน แล้วค่อยให้ใครนําไปใช้ก็ได้เหมือน template file สําหรับสร้าง Infrastructure ก็ได้

ซึ่ง Service นั้นของ AWS ก็คือ CloudFormation ที่จะทําหน้าที่สร้าง Infrastructure จาก JSON template ให้เราตามที่เราเขียนไว้ (Infrastructure as Code) โดยเราจะเรียกว่า resources ต่างๆๆที่สร้างเสร็จแล้วว่า Stack

CloudFormation Structure

CloudFormation แบ่งออกเป็นส่วนๆได้ตามนี้

  1. AWSTemplateFormatVersion
    version ของ CloudFormation ที่เราเรียกใช้ API
  2. Description
    text ที่อธิบายว่า template ทําอะไรบ้าง
  3. Metadata
    ข้อมูลเพิ่มเติมของ template
  4. Parameters
    Values ที่ส่งเข้ามาตอน runtime ของการสร้าง Infrastructure ซึ่งเราสามารถอ้างอิงจาก Resources หรือ Output section ได้
  5. Mappings
    Key-value ที่สามารถนําไปใช้เป็น Parameter ร่วมกับ Condition section ได้
  6. Conditions
    เป็นการสร้างเงื่อนไขท่ไว้เช็คว่า resource ของเราถูกสร้างขึ้นหรืออัพเดตได้ถูกต้องมั้ย
  7. Transform
    ให้มองเหมือนเป็นการเปลี่ยน Cloudformation template ไปเป็นservice ที่เจาะจงสําหรับสิ่งนั้นเลยเพื่อใช้ในการทําไรบางอย่าง เช่น สําหรับการสร้าง Lambda-based application ด้วย AWS Serverless Application Model https://github.com/awslabs/serverless-application-specification
    หรือ การทํา CodeDeploy แบบ Blue and Green deployment เราก็จะต้อง transform มัน
  8. Resources
    ใช้เพื่อในการระบุ resources ที่เราจะสร้างขึ้นมาใช้งาน เช่น EC2 S3 หรือ resource อื่นๆๆ
  9. Outputs
    ใช้เพื่อระบุในการส่งค่ากลับมาเมื่อเราสั่ง view stack’s ของเรา เช่น ใช้ CLI ในการดูข้อมูลของ stack output จะเป็นส่วนที่เราระบุค่านั้นเอง

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response