|
| 1 | +# Module 01 — Serverless App |
| 2 | + |
| 3 | +Build intuition with the `awslocal` CLI, then deploy the full Order Processing Pipeline with Terraform. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Part A — AWS CLI Basics with `awslocal` |
| 8 | + |
| 9 | +### S3 |
| 10 | + |
| 11 | +```bash |
| 12 | +# Create a bucket and upload a file |
| 13 | +awslocal s3 mb s3://workshop-receipts |
| 14 | +echo "hello localstack" > /tmp/test.txt |
| 15 | +awslocal s3 cp /tmp/test.txt s3://workshop-receipts/test.txt |
| 16 | +awslocal s3 ls s3://workshop-receipts |
| 17 | +``` |
| 18 | + |
| 19 | +### DynamoDB |
| 20 | + |
| 21 | +```bash |
| 22 | +# Create a table and put an item |
| 23 | +awslocal dynamodb create-table \ |
| 24 | + --table-name orders-scratch \ |
| 25 | + --attribute-definitions AttributeName=order_id,AttributeType=S \ |
| 26 | + --key-schema AttributeName=order_id,KeyType=HASH \ |
| 27 | + --billing-mode PAY_PER_REQUEST |
| 28 | + |
| 29 | +awslocal dynamodb put-item \ |
| 30 | + --table-name orders-scratch \ |
| 31 | + --item '{"order_id": {"S": "ord-001"}, "status": {"S": "pending"}}' |
| 32 | + |
| 33 | +awslocal dynamodb scan --table-name orders-scratch |
| 34 | +``` |
| 35 | + |
| 36 | +### SQS |
| 37 | + |
| 38 | +```bash |
| 39 | +# Create a queue and send a message |
| 40 | +awslocal sqs create-queue --queue-name workshop-queue |
| 41 | +QUEUE_URL=$(awslocal sqs get-queue-url --queue-name workshop-queue --query QueueUrl --output text) |
| 42 | +awslocal sqs send-message --queue-url $QUEUE_URL --message-body '{"test": true}' |
| 43 | +awslocal sqs receive-message --queue-url $QUEUE_URL |
| 44 | +``` |
| 45 | + |
| 46 | +### Lambda (quick smoke test) |
| 47 | + |
| 48 | +```bash |
| 49 | +# Invoke the order_handler directly (deployed in Part B) |
| 50 | +awslocal lambda invoke \ |
| 51 | + --function-name order-handler \ |
| 52 | + --payload '{"body": "{\"item\": \"book\", \"quantity\": 2}"}' \ |
| 53 | + /tmp/response.json |
| 54 | +cat /tmp/response.json |
| 55 | +``` |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Part B — Deploy with Terraform |
| 60 | + |
| 61 | +```bash |
| 62 | +cd 01-serverless-app/terraform |
| 63 | + |
| 64 | +# Initialize and deploy |
| 65 | +tflocal init |
| 66 | +tflocal apply -auto-approve |
| 67 | + |
| 68 | +# Grab the API Gateway endpoint |
| 69 | +tflocal output api_endpoint |
| 70 | +``` |
| 71 | + |
| 72 | +### Test the deployed API |
| 73 | + |
| 74 | +```bash |
| 75 | +API=$(tflocal output -raw api_endpoint) |
| 76 | + |
| 77 | +# Create an order |
| 78 | +curl -s -X POST "$API/orders" \ |
| 79 | + -H "Content-Type: application/json" \ |
| 80 | + -d '{"item": "LocalStack T-Shirt", "quantity": 1}' | python3 -m json.tool |
| 81 | + |
| 82 | +# Check DynamoDB |
| 83 | +awslocal dynamodb scan --table-name orders |
| 84 | + |
| 85 | +# Check S3 receipts |
| 86 | +awslocal s3 ls s3://order-receipts/ |
| 87 | +``` |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## What Got Deployed |
| 92 | + |
| 93 | +``` |
| 94 | +API Gateway → Lambda: order_handler → DynamoDB (orders table) |
| 95 | + → SQS (orders-queue) |
| 96 | + └→ Lambda: order_processor |
| 97 | + → DynamoDB (status update) |
| 98 | + → S3 (receipt upload) |
| 99 | + SQS DLQ ← (on processor failure) |
| 100 | +``` |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +Next: [Module 02 — E2E Testing](../02-e2e-testing/README.md) |
0 commit comments