DevOps & Cloud
0/3 sections
0%

Serverless Architecture

Serverless architecture lets you run code without managing servers. Functions execute on-demand, scale automatically, and you pay only per invocation. Perfect for event-driven, variable-load workloads.

1AWS Lambda

javascript
// Lambda function handler
export const handler = async (event, context) => {
  console.log('Event:', JSON.stringify(event, null, 2));

// API Gateway event if (event.httpMethod) { const { httpMethod, path, body } = event; const data = body ? JSON.parse(body) : null;

if (httpMethod === 'GET' && path === '/users') { const users = await db.user.findMany(); return { statusCode: 200, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(users) }; } return { statusCode: 404, body: 'Not found' }; }

// S3 event if (event.Records?.[0]?.s3) { const bucket = event.Records[0].s3.bucket.name; const key = event.Records[0].s3.object.key; await processImage(bucket, key); }

// SQS event if (event.Records?.[0]?.body) { for (const record of event.Records) { await processMessage(JSON.parse(record.body)); } }

return { statusCode: 200 }; }; ```

2Use Cases & Trade-offs

    Best for:
  • Webhooks and event processing (GitHub, Stripe, Slack)
  • Scheduled jobs (cron-like, EventBridge)
  • Image/video processing on upload
  • API backends with variable load
  • Data pipeline stages
    Not ideal for:
  • Long-running tasks (Lambda max 15 minutes)
  • Persistent connections (WebSockets require workarounds)
  • CPU-intensive work (limited compute, pricey)
  • Low-latency requirements (cold start: 100ms-1s)

Cold Start Mitigation: ```javascript // Warm-up: initialize clients outside handler (runs once per container) const db = new PrismaClient(); // outside handler = warm const redis = createClient({ url: process.env.REDIS_URL }); await redis.connect();

export const handler = async (event) => { // db and redis already connected on warm invocations };

// Provisioned Concurrency: keep N containers warm (pay even when idle) // SnapStart (Java): snapshot initialized state for faster start ```

Serverless Framework: ``yaml # serverless.yml service: my-api provider: name: aws runtime: nodejs20.x region: us-east-1 functions: api: handler: src/handler.handler events: - http: { path: /{proxy+}, method: ANY } environment: DATABASE_URL: ${env:DATABASE_URL} ``

3Serverless Framework & SAM

yaml
# serverless.yml full production config
service: my-api
frameworkVersion: "3"

provider: name: aws runtime: nodejs20.x region: us-east-1 memorySize: 512 timeout: 29 logRetentionInDays: 30

environment: TABLE_NAME: !Ref UsersTable STAGE: ${sls:stage}

iam: role: statements: - Effect: Allow Action: - dynamodb:GetItem - dynamodb:PutItem - dynamodb:UpdateItem - dynamodb:DeleteItem - dynamodb:Query Resource: !GetAtt UsersTable.Arn

functions: api: handler: dist/handler.main events: - httpApi: path: /api/{proxy+} method: ANY layers: - !Ref DepsLayer # keep layer size small

processQueue: handler: dist/queue.handler reservedConcurrency: 10 # limit concurrency events: - sqs: arn: !GetAtt JobQueue.Arn batchSize: 10 maximumBatchingWindow: 30 functionResponseType: ReportBatchItemFailures

cleanup: handler: dist/cleanup.handler events: - schedule: rate: rate(1 hour) enabled: true

resources: Resources: UsersTable: Type: AWS::DynamoDB::Table Properties: BillingMode: PAY_PER_REQUEST AttributeDefinitions: - AttributeName: pk AttributeType: S - AttributeName: sk AttributeType: S KeySchema: - AttributeName: pk KeyType: HASH - AttributeName: sk KeyType: RANGE TimeToLiveSpecification: AttributeName: ttl Enabled: true ```

Explore the Full Portfolio

This is the complete portfolio of Sufi Khan Sulaiman, a technology leader specialising in B2B commerce and digital automation. Start from the Home page for the overview, then move through two decades of career experience across FLIR Systems, Lorex Technology, and 1c Platform, and the full catalogue of project case studies spanning headless commerce migrations, AI recommendation engines, and multi-channel fulfilment systems.

The skills and certifications page maps the technical and leadership capabilities behind the work, while the articles and the knowledge base break down the thinking into actionable frameworks. For hands-on learning, the tutorials and applications sections cover practical builds from front-end fundamentals to full-stack web apps.

For consulting engagement, the expertise page outlines service offerings, the ecommerce hub covers platform architecture and automation strategy, and the ecommerce guide (PDF) is a downloadable 55-page field manual. When you are ready to talk, the contact page is the direct line.