AWS SAM dan CDK untuk serverless dan IaC

Mengotomatisasi Deployment di AWS

Dunieski Otano

Amazon Web Services Solutions Architect

Berkas YAML 2.000 baris

yaml

  • Satu Lambda + API Gateway membengkak jadi 2.000 baris YAML
  • Setiap peran IAM, grup log, dan izin ditulis eksplisit
  • Salah ketik di tengah kebijakan izin
  • SAM dan CDK merangkum ini jadi beberapa baris
Mengotomatisasi Deployment di AWS

Sekilas AWS SAM

sam

  • SAM adalah ekstensi CloudFormation untuk serverless
  • Tipe resource ringkas: AWS::Serverless::Function, ::Api
  • SAM CLI membangun, mengemas, dan menerapkan
  • Template diubah menjadi CloudFormation biasa
Mengotomatisasi Deployment di AWS

Alur kerja SAM

workflow

  • sam init: buat kerangka proyek dari template
  • sam validate: periksa template sebelum build
  • sam build: kompilasi dan kemas kode
  • sam deploy: kirim ke stack CloudFormation
Mengotomatisasi Deployment di AWS

Sekilas AWS CDK

  • Tulis infrastruktur dalam TypeScript, JavaScript, Python, Java, C#, Go
  • Kompilasi ke CloudFormation dengan cdk synth
  • Terapkan dengan cdk deploy; rebuild saat kode berubah
  • Konsep stack dan resource sama seperti CloudFormation

cdk

Mengotomatisasi Deployment di AWS

Level construct CDK

  • L1: bungkus 1 banding 1 untuk resource CloudFormation
  • L2: construct terkurasi dengan default yang masuk akal
  • L3: pola yang mengemas banyak resource
  • Level lebih tinggi = lebih sedikit baris, kontrol lebih kecil

construct

Mengotomatisasi Deployment di AWS

Kapan memakai masing-masing

  • CloudFormation mentah: kontrol penuh, ramah ops
  • SAM: aplikasi serverless murni, jalur tercepat
  • CDK: infra kompleks, tim berbasis bahasa pemrograman
  • Ketiganya menerapkan dengan cara yang sama di bawahnya

each

Mengotomatisasi Deployment di AWS

Ketiganya menerapkan sebagai CloudFormation

funnel

  • SAM mentransformasi ke CloudFormation
  • CDK mensintesis ke CloudFormation
  • Stack hasilnya memakai events, drift, change sets yang sama
  • Rollback bekerja sama terlepas dari toolkitya
Mengotomatisasi Deployment di AWS

Ayo berlatih!

Mengotomatisasi Deployment di AWS

Preparing Video For Download...