$npx -y skills add SamarthaKV29/antigravity-god-mode --skill aws-serverlessSpecialized skill for building production-ready serverless applications on AWS. Covers Lambda functions, API Gateway, DynamoDB, SQS/SNS event-driven patterns, SAM/CDK deployment, and cold start optimization.
| 1 | # AWS Serverless |
| 2 | |
| 3 | ## Patterns |
| 4 | |
| 5 | ### Lambda Handler Pattern |
| 6 | |
| 7 | Proper Lambda function structure with error handling |
| 8 | |
| 9 | **When to use**: ['Any Lambda function implementation', 'API handlers, event processors, scheduled tasks'] |
| 10 | |
| 11 | ```python |
| 12 | ```javascript |
| 13 | // Node.js Lambda Handler |
| 14 | // handler.js |
| 15 | |
| 16 | // Initialize outside handler (reused across invocations) |
| 17 | const { DynamoDBClient } = require('@aws-sdk/client-dynamodb'); |
| 18 | const { DynamoDBDocumentClient, GetCommand } = require('@aws-sdk/lib-dynamodb'); |
| 19 | |
| 20 | const client = new DynamoDBClient({}); |
| 21 | const docClient = DynamoDBDocumentClient.from(client); |
| 22 | |
| 23 | // Handler function |
| 24 | exports.handler = async (event, context) => { |
| 25 | // Optional: Don't wait for event loop to clear (Node.js) |
| 26 | context.callbackWaitsForEmptyEventLoop = false; |
| 27 | |
| 28 | try { |
| 29 | // Parse input based on event source |
| 30 | const body = typeof event.body === 'string' |
| 31 | ? JSON.parse(event.body) |
| 32 | : event.body; |
| 33 | |
| 34 | // Business logic |
| 35 | const result = await processRequest(body); |
| 36 | |
| 37 | // Return API Gateway compatible response |
| 38 | return { |
| 39 | statusCode: 200, |
| 40 | headers: { |
| 41 | 'Content-Type': 'application/json', |
| 42 | 'Access-Control-Allow-Origin': '*' |
| 43 | }, |
| 44 | body: JSON.stringify(result) |
| 45 | }; |
| 46 | } catch (error) { |
| 47 | console.error('Error:', JSON.stringify({ |
| 48 | error: error.message, |
| 49 | stack: error.stack, |
| 50 | requestId: context.awsRequestId |
| 51 | })); |
| 52 | |
| 53 | return { |
| 54 | statusCode: error.statusCode || 500, |
| 55 | headers: { 'Content-Type': 'application/json' }, |
| 56 | body: JSON.stringify({ |
| 57 | error: error.message || 'Internal server error' |
| 58 | }) |
| 59 | }; |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | async function processRequest(data) { |
| 64 | // Your business logic here |
| 65 | const result = await docClient.send(new GetCommand({ |
| 66 | TableName: process.env.TABLE_NAME, |
| 67 | Key: { id: data.id } |
| 68 | })); |
| 69 | return result.Item; |
| 70 | } |
| 71 | ``` |
| 72 | |
| 73 | ```python |
| 74 | # Python Lambda Handler |
| 75 | # handler.py |
| 76 | |
| 77 | import json |
| 78 | import os |
| 79 | import logging |
| 80 | import boto3 |
| 81 | from botocore.exceptions import ClientError |
| 82 | |
| 83 | # Initialize outside handler (reused across invocations) |
| 84 | logger = logging.getLogger() |
| 85 | logger.setLevel(logging.INFO) |
| 86 | |
| 87 | dynamodb = boto3.resource('dynamodb') |
| 88 | table = dynamodb.Table(os.environ['TABLE_NAME']) |
| 89 | |
| 90 | def handler(event, context): |
| 91 | try: |
| 92 | # Parse i |
| 93 | ``` |
| 94 | |
| 95 | ### API Gateway Integration Pattern |
| 96 | |
| 97 | REST API and HTTP API integration with Lambda |
| 98 | |
| 99 | **When to use**: ['Building REST APIs backed by Lambda', 'Need HTTP endpoints for functions'] |
| 100 | |
| 101 | ```javascript |
| 102 | ```yaml |
| 103 | # template.yaml (SAM) |
| 104 | AWSTemplateFormatVersion: '2010-09-09' |
| 105 | Transform: AWS::Serverless-2016-10-31 |
| 106 | |
| 107 | Globals: |
| 108 | Function: |
| 109 | Runtime: nodejs20.x |
| 110 | Timeout: 30 |
| 111 | MemorySize: 256 |
| 112 | Environment: |
| 113 | Variables: |
| 114 | TABLE_NAME: !Ref ItemsTable |
| 115 | |
| 116 | Resources: |
| 117 | # HTTP API (recommended for simple use cases) |
| 118 | HttpApi: |
| 119 | Type: AWS::Serverless::HttpApi |
| 120 | Properties: |
| 121 | StageName: prod |
| 122 | CorsConfiguration: |
| 123 | AllowOrigins: |
| 124 | - "*" |
| 125 | AllowMethods: |
| 126 | - GET |
| 127 | - POST |
| 128 | - DELETE |
| 129 | AllowHeaders: |
| 130 | - "*" |
| 131 | |
| 132 | # Lambda Functions |
| 133 | GetItemFunction: |
| 134 | Type: AWS::Serverless::Function |
| 135 | Properties: |
| 136 | Handler: src/handlers/get.handler |
| 137 | Events: |
| 138 | GetItem: |
| 139 | Type: HttpApi |
| 140 | Properties: |
| 141 | ApiId: !Ref HttpApi |
| 142 | Path: /items/{id} |
| 143 | Method: GET |
| 144 | Policies: |
| 145 | - DynamoDBReadPolicy: |
| 146 | TableName: !Ref ItemsTable |
| 147 | |
| 148 | CreateItemFunction: |
| 149 | Type: AWS::Serverless::Function |
| 150 | Properties: |
| 151 | Handler: src/handlers/create.handler |
| 152 | Events: |
| 153 | CreateItem: |
| 154 | Type: HttpApi |
| 155 | Properties: |
| 156 | ApiId: !Ref HttpApi |
| 157 | Path: /items |
| 158 | Method: POST |
| 159 | Policies: |
| 160 | - DynamoDBCrudPolicy: |
| 161 | TableName: !Ref ItemsTable |
| 162 | |
| 163 | # DynamoDB Table |
| 164 | ItemsTable: |
| 165 | Type: AWS::DynamoDB::Table |
| 166 | Properties: |
| 167 | AttributeDefinitions: |
| 168 | - AttributeName: id |
| 169 | AttributeType: S |
| 170 | KeySchema: |
| 171 | - AttributeName: id |
| 172 | KeyType: HASH |
| 173 | BillingMode: PAY_PER_REQUEST |
| 174 | |
| 175 | Outputs: |
| 176 | ApiUrl: |
| 177 | Value: !Sub "https://${HttpApi}.execute-api.${AWS::Region}.amazonaws.com/prod" |
| 178 | ``` |
| 179 | |
| 180 | ```javascript |
| 181 | // src/handlers/get.js |
| 182 | const { getItem } = require('../lib/dynamodb'); |
| 183 | |
| 184 | exports.handler = async (event) => { |
| 185 | const id = event.pathParameters?.id; |
| 186 | |
| 187 | if (!id) { |
| 188 | return { |
| 189 | statusCode: 400, |
| 190 | body: JSON.stringify({ error: 'Missing id parameter' }) |
| 191 | }; |
| 192 | } |
| 193 | |
| 194 | const item = |
| 195 | ``` |
| 196 | |
| 197 | ### Event-Driven SQS Pattern |
| 198 | |
| 199 | Lambda triggered by SQS for reliable async processing |
| 200 | |
| 201 | **When to use**: ['Decoupled, asynchronous processing', 'Need retry logic and DLQ', 'Processing messages in batches'] |
| 202 | |
| 203 | ```python |
| 204 | ```yaml |
| 205 | # template.yaml |
| 206 | Resources: |
| 207 | ProcessorFuncti |