Panduan Cloud Engineer: Infrastruktur Serverless AWS Lambda, SQS DLQ & DynamoDB dengan IaC

Merancang arsitektur serverless berbasis event—di mana antrean Amazon SQS memicu fungsi AWS Lambda yang menulis ke tabel DynamoDB—membutuhkan keselarasan antara VisibilityTimeout, pelaporan kegagalan parsial batch, dan antrean Dead-Letter Queue (DLQ). Sebagai Senior Cloud Engineer, berikut adalah cara saya mendefinisikan tumpukan serverless produksi menggunakan CloudFormation dan Terraform.

1. Konfigurasi SQS + Lambda + DLQ dengan ReportBatchItemFailures

Menetapkan VisibilityTimeout sebesar 6 kali batas waktu Lambda serta mengaktifkan ReportBatchItemFailures memastikan bahwa jika satu pesan dalam batch gagal, 9 pesan lain yang berhasil tidak akan diproses ulang.

2. Penulisan Kondisional Idempoten di DynamoDB

Penggunaan ConditionExpression="attribute_not_exists(event_id)" pada DynamoDB menjamin pengiriman pesan SQS lebih dari sekali (at-least-once) tidak pernah menimbulkan duplikasi transaksi.

3. Bermitra dengan Senior Cloud Engineer

Jelajahi Panduan Utama Cloud Engineer, baca Panduan Impor Infrastruktur ke Terraform, atau pesan Sprint Arsitektur Serverless 1 Hari.

Implementasi Kode Produksi & Konfigurasi Teknis

Berikut adalah implementasi kode produksi lengkap dan konfigurasi teknis untuk arsitektur Panduan Cloud Engineer: Infrastruktur Serverless AWS Lambda, SQS DLQ & DynamoDB dengan IaC:

AWSTemplateFormatVersion: '2010-09-09'
Description: Production Event-Driven SQS + Lambda + DynamoDB Stack

Resources:
  EventsDeadLetterQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: prod-order-events-dlq
      MessageRetentionPeriod: 1209600 # 14 days
      KmsMasterKeyId: alias/aws/sqs

  EventsPrimaryQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: prod-order-events
      VisibilityTimeout: 180 # 6x Lambda 30s timeout
      KmsMasterKeyId: alias/aws/sqs
      RedrivePolicy:
        deadLetterTargetArn: !GetAtt EventsDeadLetterQueue.Arn
        maxReceiveCount: 3

  OrderProcessorMapping:
    Type: AWS::Lambda::EventSourceMapping
    Properties:
      EventSourceArn: !GetAtt EventsPrimaryQueue.Arn
      FunctionName: !GetAtt OrderProcessorFunction.Arn
      BatchSize: 10
      MaximumBatchingWindowInSeconds: 2
      FunctionResponseTypes:
        - ReportBatchItemFailures

Checklist Arsitektur Produksi (Cloud Engineer)

Dalam menerapkan solusi Panduan Cloud Engineer: Infrastruktur Serverless AWS Lambda, SQS DLQ & DynamoDB dengan IaC (Cloud Engineer, AWS, Serverless, Terraform, CloudFormation, DynamoDB) pada lingkungan produksi berskala enterprise sebagai Cloud Engineer, pastikan standar rekayasa berikut terpenuhi:


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 25+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs