CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pulumi--aws

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources with infrastructure-as-code.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

overview.mddocs/compute/

AWS Compute Services Overview

Guide to selecting and using AWS compute services with Pulumi.

Service Categories

Serverless Compute

Run code without managing servers - Automatic scaling, pay-per-use

  • Lambda - Event-driven functions, millisecond billing
  • Fargate - Serverless containers (ECS/EKS)
  • App Runner - Fully managed web applications and APIs

Container Orchestration

Deploy and manage containerized applications

  • ECS - AWS-native container orchestration
  • EKS - Managed Kubernetes service
  • ECR - Container image registry
  • App Mesh - Service mesh for microservices

Virtual Machines

Full control over compute instances

  • EC2 - Virtual servers with customizable configurations
  • Auto Scaling - Automatic capacity management
  • Lightsail - Simple VPS instances

Batch & High-Performance

Large-scale parallel workloads

  • Batch - Managed batch processing
  • EMR - Big data processing (Hadoop, Spark)
  • ParallelCluster - HPC clusters

Decision Tree

Choose Your Compute Service

Start: What are you running?

┌─ Web application or API
│  ├─ Containerized?
│  │  ├─ Yes → Need Kubernetes? → Yes: EKS | No: ECS/Fargate
│  │  └─ No → Simple deployment? → Yes: App Runner | No: EC2 + ALB
│  └─ Static site → CloudFront + S3
│
┌─ Event-driven processing
│  ├─ < 15 min execution → Lambda
│  ├─ Stateful workflows → Step Functions + Lambda/Fargate
│  └─ Long-running → ECS/EKS
│
┌─ Batch processing
│  ├─ Big data → EMR
│  ├─ Video/media → Batch + GPU instances
│  └─ General batch → Batch or Lambda
│
┌─ Machine learning
│  ├─ Training → SageMaker or EC2 with GPUs
│  ├─ Inference → Lambda, SageMaker, or ECS
│  └─ Batch predictions → Batch
│
└─ Specific requirements
   ├─ Need specific OS/kernel → EC2
   ├─ Compliance/isolation → EC2 Dedicated Hosts
   ├─ High-performance computing → ParallelCluster
   └─ Legacy migration → EC2

Service Selection Guide

Use Lambda When

  • Event-driven workloads (S3 uploads, API requests, scheduled tasks)
  • Execution time < 15 minutes
  • Intermittent traffic patterns
  • Want zero operational overhead
  • Need automatic scaling to zero

Example use cases:

  • API backends (with API Gateway)
  • Image/video processing triggers
  • Scheduled data processing
  • Webhook handlers
  • Real-time stream processing

Anti-patterns:

  • Long-running processes (>15 min)
  • High-frequency, sustained workloads (EC2 may be cheaper)
  • Applications requiring persistent connections
  • Heavy stateful applications

Use ECS When

  • Running containerized applications
  • Need AWS-native integration
  • Want managed container orchestration
  • Prefer simpler setup than Kubernetes
  • Running microservices architecture

Example use cases:

  • Microservices deployments
  • Web applications with containers
  • Background workers
  • Batch processing jobs
  • Service-oriented architectures

ECS vs Fargate:

  • ECS on EC2 - More control, potentially lower cost at scale
  • ECS on Fargate - Serverless, no instance management, simpler

Use EKS When

  • Already using Kubernetes
  • Need Kubernetes-specific features
  • Multi-cloud or hybrid deployments
  • Complex orchestration requirements
  • Large team with Kubernetes expertise

Example use cases:

  • Existing Kubernetes workloads
  • Complex microservices with service mesh
  • Multi-cloud deployments
  • Applications requiring Kubernetes operators
  • GitOps workflows

Consider costs:

  • EKS control plane: $0.10/hour (~$73/month)
  • Plus worker node costs (EC2 or Fargate)

Use EC2 When

  • Need specific OS or kernel versions
  • Require persistent local storage
  • Running licensed software tied to VMs
  • High-performance computing needs
  • 24/7 steady-state workloads (use Reserved Instances)

Instance selection:

  • General purpose (t3, m5) - Balanced, web servers, small DBs
  • Compute optimized (c5) - CPU-intensive, batch processing
  • Memory optimized (r5, x1) - In-memory DBs, big data
  • GPU instances (p3, g4) - ML training, graphics
  • ARM-based (t4g, m6g) - Cost-effective for compatible workloads

Use Auto Scaling When

  • Variable traffic patterns
  • Need high availability across AZs
  • Want automatic failure recovery
  • Cost optimization for variable loads

Scaling strategies:

  • Target tracking - Maintain metric at target (CPU, request count)
  • Step scaling - Scale based on alarm thresholds
  • Scheduled - Predictable traffic patterns
  • Predictive - ML-based forecasting

Use Batch When

  • Large-scale parallel jobs
  • Job scheduling and dependencies
  • Dynamic compute provisioning
  • Video rendering, simulation, analysis

Benefits:

  • Automatic job queuing and scheduling
  • Dynamic resource provisioning
  • Spot instance support
  • Job dependencies and retries

Common Patterns

Pattern 1: Serverless API

Lambda + API Gateway + DynamoDB

import * as aws from "@pulumi/aws";

// Lambda function
const handler = new aws.lambda.Function("api", {
    runtime: "nodejs20.x",
    handler: "index.handler",
    role: lambdaRole.arn,
    code: new pulumi.asset.FileArchive("./app"),
});

// API Gateway
const api = new aws.apigatewayv2.Api("api", {
    protocolType: "HTTP",
});

const integration = new aws.apigatewayv2.Integration("integration", {
    apiId: api.id,
    integrationType: "AWS_PROXY",
    integrationUri: handler.arn,
});

const route = new aws.apigatewayv2.Route("route", {
    apiId: api.id,
    routeKey: "POST /users",
    target: pulumi.interpolate`integrations/${integration.id}`,
});

Use when: Building REST APIs, microservices, mobile backends

Pattern 2: Containerized Web App

ECS Fargate + ALB

// ECS cluster
const cluster = new aws.ecs.Cluster("app-cluster");

// Task definition
const taskDef = new aws.ecs.TaskDefinition("app-task", {
    family: "app",
    cpu: "256",
    memory: "512",
    networkMode: "awsvpc",
    requiresCompatibilities: ["FARGATE"],
    containerDefinitions: JSON.stringify([{
        name: "app",
        image: "nginx:latest",
        portMappings: [{ containerPort: 80 }],
    }]),
});

// Service with load balancer
const service = new aws.ecs.Service("app-service", {
    cluster: cluster.arn,
    taskDefinition: taskDef.arn,
    desiredCount: 2,
    launchType: "FARGATE",
    networkConfiguration: {
        subnets: subnetIds,
        securityGroups: [securityGroup.id],
    },
    loadBalancers: [{
        targetGroupArn: targetGroup.arn,
        containerName: "app",
        containerPort: 80,
    }],
});

Use when: Running containerized web apps, APIs, microservices

Pattern 3: High-Availability EC2

Auto Scaling Group + ALB

// Launch template
const launchTemplate = new aws.ec2.LaunchTemplate("app-template", {
    imageId: "ami-0c55b159cbfafe1f0",
    instanceType: "t3.micro",
    userData: Buffer.from(`#!/bin/bash
        yum update -y
        yum install -y httpd
        systemctl start httpd
    `).toString("base64"),
});

// Auto Scaling Group
const asg = new aws.autoscaling.Group("app-asg", {
    launchTemplate: {
        id: launchTemplate.id,
        version: "$Latest",
    },
    minSize: 2,
    maxSize: 10,
    desiredCapacity: 2,
    vpcZoneIdentifiers: subnetIds,
    targetGroupArns: [targetGroup.arn],
    healthCheckType: "ELB",
    healthCheckGracePeriod: 300,
});

// Scaling policy
const scaleUp = new aws.autoscaling.Policy("scale-up", {
    autoscalingGroupName: asg.name,
    scalingAdjustment: 1,
    adjustmentType: "ChangeInCapacity",
    cooldown: 300,
});

Use when: High-availability web apps, variable traffic, need HA

Pattern 4: Event Processing Pipeline

S3 + Lambda + SQS + DynamoDB

// S3 bucket for uploads
const bucket = new aws.s3.BucketV2("uploads");

// SQS queue for processing
const queue = new aws.sqs.Queue("processing-queue", {
    visibilityTimeoutSeconds: 300,
});

// Lambda processor
const processor = new aws.lambda.Function("processor", {
    runtime: "python3.11",
    handler: "lambda_function.handler",
    role: role.arn,
    code: new pulumi.asset.FileArchive("./processor"),
    environment: {
        variables: {
            QUEUE_URL: queue.url,
        },
    },
});

// S3 notification to Lambda
const notification = new aws.s3.BucketNotification("notification", {
    bucket: bucket.id,
    lambdaFunctions: [{
        lambdaFunctionArn: processor.arn,
        events: ["s3:ObjectCreated:*"],
    }],
});

Use when: Processing uploads, ETL pipelines, event-driven workflows

Pattern 5: Kubernetes Cluster

EKS + Managed Node Groups

// EKS cluster
const cluster = new aws.eks.Cluster("k8s-cluster", {
    roleArn: clusterRole.arn,
    vpcConfig: {
        subnetIds: subnetIds,
    },
});

// Managed node group
const nodeGroup = new aws.eks.NodeGroup("app-nodes", {
    clusterName: cluster.name,
    nodeRoleArn: nodeRole.arn,
    subnetIds: subnetIds,
    scalingConfig: {
        desiredSize: 2,
        minSize: 1,
        maxSize: 4,
    },
    instanceTypes: ["t3.medium"],
});

// Export kubeconfig
export const kubeconfig = cluster.kubeconfig;

Use when: Need Kubernetes, complex orchestration, multi-cloud

Cost Optimization

Savings Strategies

  1. Right-sizing

    • Monitor CPU/memory utilization
    • Use Compute Optimizer recommendations
    • Start small, scale up as needed
  2. Reserved Instances & Savings Plans

    • 1-year or 3-year commitments
    • Up to 72% savings vs on-demand
    • Best for steady-state workloads
  3. Spot Instances

    • Up to 90% savings vs on-demand
    • Good for fault-tolerant workloads
    • Use with Auto Scaling or Batch
  4. Lambda Optimization

    • Use appropriate memory allocation
    • Consider Lambda Graviton2 (ARM)
    • Minimize cold starts
    • Use Provisioned Concurrency for latency-sensitive apps
  5. Container Optimization

    • Fargate Spot for dev/test
    • EC2 Spot for batch workloads
    • Use ARM-based instances (Graviton)
    • Right-size task CPU/memory

Quick Links

Core Services

  • EC2 - Virtual Servers
  • Lambda - Serverless Functions
  • ECS - Container Service
  • EKS - Kubernetes Service
  • Auto Scaling

Related Services

Guides

See Also

Install with Tessl CLI

npx tessl i tessl/npm-pulumi--aws

docs

index.md

quickstart.md

README.md

tile.json