docs/scf/examples/deno.md
This example demonstrates the development and deployment of a simple, performant web application built with Deno V2, the Oak framework, and TypeScript. The Serverless Container Framework (SCF) enables this application to be deployed to either AWS Lambda or AWS ECS Fargate without rearchitecting.
awsLambda) or on AWS Fargate ECS (awsFargateEcs). A multi-stage Dockerfile is provided to support these configurations.Before getting started, make sure you have:
npm i -g serverless
For more information on setting up AWS credentials, see the SCF Getting Started guide.
At the root of the example, a serverless.containers.yml file defines the project configuration:
name: deno
deployment:
type: [email protected]
containers:
service:
src: ./service
routing:
pathPattern: /*
pathHealthCheck: /health
environment:
HELLO: world
compute:
type: awsLambda # Can be switched to awsFargateEcs
build:
options:
- --target=awsLambda # Ensure you match the compute type set above. Sets the target build stage for the Dockerfile.
This file specifies:
deno, which is used as a prefix to namespace resources in your AWS account../service directory./*) with a defined health check endpoint (/health).HELLO) is provided.awsLambda but can be switched to awsFargateEcs as needed.For more details on SCF configuration options, see the SCF Configuration documentation.
example-deno/
├── serverless.containers.yml # SCF project configuration file
└── service/
├── Dockerfile # Multi-stage Dockerfile for AWS Lambda and Fargate builds
├── deno.json # Deno configuration and task definitions
├── deno.lock # Deno lock file
└── src/
├── index.ts # Main application entrypoint (uses Oak and oakCors)
└── public/
└── css/
└── styles.css # Static assets (CSS, images, etc.)
Serverless Container Framework includes a rich development mode that emulates AWS ALB routing, AWS Lambda, and AWS Fargate ECS locally, including AWS Application Load Balancer emulation. This mode allows you to test routing, static asset delivery, and health check endpoints while running your container with Deno, which proxies requests on port 8080.
Run the following command to start local development mode:
serverless dev
This command watches for changes and rebuilds the container as needed.
For more information on local development with SCF, see the SCF Development documentation.
To deploy this example with SCF, open your terminal in the example-deno directory.
Execute the following command to deploy your container to AWS:
serverless deploy
This command builds the Deno container image using the provided Dockerfile and provisions AWS resources (ALB, VPC, Lambda function, or ECS Fargate service).
If you switch compute types, ensure that you set the build --target option to the corresponding compute type, since the Dockerfile declares multiple build configurations.
Once deployed, SCF will output the URLs and endpoints (such as the ALB endpoint) for your application.
Access the application via the provided URL to see your Deno app live.
For more details on deployment options and processes, see the SCF Deployment documentation.
Serverless Container Framework supports the Serverless Framework Variables system to reference infrastructure details, secrets, and more from various sources:
containers:
service:
environment:
# Simple static value
SERVICE_NAME: deno-service
# Environment variable reference
HELLO: ${env:HELLO_VALUE}
# AWS Systems Manager Parameter Store reference
API_ENDPOINT: ${aws:ssm:/path/to/api/endpoint}
# AWS Secrets Manager reference
API_KEY: ${aws:secretsmanager:DenoApiSecret.key}
# HashiCorp Vault reference
SERVICE_TOKEN: ${vault:secret/data/service/credentials.token}
# HashiCorp Terraform state reference
DATABASE_URL: ${terraform:outputs:database_url}
# S3 bucket value reference
CONFIG_JSON: ${aws:s3:config-bucket/deno-config.json}
# CloudFormation stack output reference
VPC_ID: ${aws:cf:networking-stack.VpcIdOutput}
For more details on using variables, see the Serverless Framework Variables documentation.
To remove the deployed containers, run:
serverless remove
To remove all AWS resources, including shared infrastructure, use:
serverless remove --force --all