Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

AWS Serverless Application

The AWS Serverless Application template scaffolds a Pulumi project that deploys a serverless web application to AWS. It provisions an Amazon S3 bucket for static website hosting, an AWS Lambda function for the application backend, and an Amazon API Gateway REST API that routes requests to the static content and the Lambda function. The template ships with a placeholder web page that displays the current time so the project deploys end to end out of the box.

Architecture diagram of the AWS Serverless Application template AWS API GatewayREST API S3 Bucket Lambda Function

Before you begin#

Create a new project#

Create a new project using the template in the language of your choice:

Terminal window
mkdir my-serverless-app && cd my-serverless-app
pulumi new serverless-aws-typescript

pulumi new walks you through creating and configuring a new project and stack. A stack is an instance of a project and you can have many of them — dev, staging, prod — each with its own configuration settings.

Then it asks for the template’s one setting:

KeyDescriptionDefault
aws:regionThe AWS region to deploy intous-west-2
You can change these settings later with pulumi config set:
Terminal window
pulumi config set aws:region <value>

Press Enter to keep the default.

When setup completes, you’ll see a few key files:

  • Pulumi.yaml names the project and the language it’s written in.
  • Pulumi.dev.yaml holds the dev stack’s settings, including the values you just entered.
  • index.ts is the program: the code that declares your cloud resources.

Deploy the project#

Deploy with pulumi up. It starts with a preview of what it’s about to create and asks before it changes anything. Choose yes to deploy.

Terminal window
pulumi up

Pulumi adds a random suffix to most resource names, so the Lambda function fn becomes something like fn-4f8a2c1. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.

When it finishes, Pulumi prints the stack’s outputs, values it only knows once the resources exist:

url

The HTTP URL for the application.

Read one any time with pulumi stack output <name>, or pass it to another command. This opens the app in your browser:

Terminal window
open $(pulumi stack output url)

The page gets the time from the Lambda function at the /date path. Call it from the terminal with curl; it prints the current time:

Terminal window
curl -s "$(pulumi stack output url)date"

Customize the project#

The template has no configuration settings of its own; aws:region is the only one pulumi new sets. It deploys the website from the www folder.

The Lambda function’s code is the callback in index.ts.

Using your own web content#

If you already have a website you’d like to deploy, you can do so by replacing the contents of the www folder and redeploying with pulumi up.

Customizing the application’s functionality#

You can customize the placeholder website by editing the Lambda function to perform another action, such as displaying a countdown to a future time. You can also add new functionality by creating a new Lambda function, adding a new path to the REST API, and updating the HTML to call the new path.

To start small, change the format of the time the function returns:

In index.ts:

const fn = new aws.lambda.CallbackFunction("fn", {
callback: async (ev, ctx) => {
return {
statusCode: 200,
body: new Date().toISOString(),
body: new Date().toUTCString(),
};

Deploy the change and call /date again:

Terminal window
pulumi up
curl -s "$(pulumi stack output url)date"

The time now comes back like Wed, 21 Oct 2026 14:05:09 GMT.

To see what else you can add, browse the AWS provider in the Pulumi Registry.

Cleaning up#

You can cleanly destroy the stack and all of its infrastructure with pulumi destroy:

Terminal window
pulumi destroy

Learn more#

Related

The infrastructure as code platform for any cloud.