aws-serverless-patterns

Apply AWS serverless patterns with Lambda, API Gateway, DynamoDB, and Step Functions. Use for event-driven architectures, APIs, and scalable applications.

coppermare/skillverse1 installsMITSynced Aug 22

Works with

Claude CodeCursorCodex CLIGitHub CopilotGemini CLI
---
name: aws-serverless-patterns
description: Apply AWS serverless patterns with Lambda, API Gateway, DynamoDB, and Step Functions. Use for event-driven architectures, APIs, and scalable applications.
license: MIT
---

# AWS Serverless Patterns

Build scalable serverless applications on AWS.

## Core Services

- **Lambda**: Serverless compute
- **API Gateway**: REST and WebSocket APIs
- **DynamoDB**: NoSQL database
- **S3**: Object storage
- **SQS/SNS**: Messaging
- **Step Functions**: Orchestration

## Patterns

### Lambda Function Handler
```python
import json
import boto3

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Users')

def lambda_handler(event, context):
    try:
        user_id = event['pathParameters']['id']
        
        response = table.get_item(Key={'userId': user_id})
        
        if 'Item' not in response:
            return {
                'statusCode': 404,
                'body': json.dumps({'error': 'User not found'})
            }
        
        return {
            'statusCode': 200,
            'body': json.dumps(response['Item'])
        }
    except Exception as e:
        return {
            'statusCode': 500,
            'body': json.dumps({'error': str(e)})
        }
```

### API Gateway Integration
```yaml
# serverless.yml
service: user-api

provider:
  name: aws
  runtime: python3.9
  environment:
    USERS_TABLE: ${self:service}-users-${self:provider.stage}

functions:
  getUser:
    handler: handler.get_user
    events:
      - http:
          path: users/{id}
          method: get
          cors: true

resources:
  Resources:
    UsersTable:
      Type: AWS::DynamoDB::Table
      Properties:
        TableName: ${self:provider.environment.USERS_TABLE}
        BillingMode: PAY_PER_REQUEST
        AttributeDefinitions:
          - AttributeName: userId
            AttributeType: S
        KeySchema:
          - AttributeName: userId
            KeyType: HASH
```

### Event-Driven Pattern
```python
# SQS + Lambda pattern
def process_order(event, context):
    for record in event['Records']:
        message = json.loads(record['body'])
        order_id = message['orderId']
        
        # Process order
        process_payment(order_id)
        update_inventory(order_id)
        send_confirmation(order_id)
```

## Best Practices

- Use environment variables for configuration
- Implement proper error handling and retries
- Set appropriate memory and timeout settings
- Use Lambda layers for shared dependencies
- Implement CloudWatch logging and monitoring
- Use X-Ray for distributed tracing
- Follow least privilege IAM policies

## Resources
- AWS Serverless Application Repository
- Serverless Framework Documentation
- AWS Well-Architected Framework

More DevOps & Infrastructure skills

← All DevOps & Infrastructure skills

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY