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.
Before you begin#
- The Pulumi CLI
- An AWS account
- The Pulumi CLI
- An AWS account
- The Pulumi CLI
- An AWS account
- Go installed locally
- The Pulumi CLI
- An AWS account
- .NET installed locally
- The Pulumi CLI v3.256.0 or later; Pulumi HCL needs no separate language runtime
- An AWS account
Create a new project#
Create a new project using the template in the language of your choice:
mkdir my-serverless-app && cd my-serverless-apppulumi new serverless-aws-typescriptmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-aws-pythonmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-aws-gomkdir my-serverless-app && cd my-serverless-apppulumi new serverless-aws-csharpmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-aws-yamlmkdir my-serverless-app && cd my-serverless-apppulumi new serverless-aws-hclpulumi 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:
| Key | Description | Default |
|---|---|---|
| aws:region | The AWS region to deploy into | us-west-2 |
pulumi config set:
pulumi config set aws:region <value>| Key | Description | Default |
|---|---|---|
| aws:region | The AWS region to deploy into | us-west-2 |
pulumi config set:
pulumi config set aws:region <value>| Key | Description | Default |
|---|---|---|
| aws:region | The AWS region to deploy into | us-west-2 |
pulumi config set:
pulumi config set aws:region <value>| Key | Description | Default |
|---|---|---|
| aws:region | The AWS region to deploy into | us-west-2 |
pulumi config set:
pulumi config set aws:region <value>| Key | Description | Default |
|---|---|---|
| aws:region | The AWS region to deploy into | us-west-2 |
pulumi config set:
pulumi config set aws:region <value>| Key | Description | Default |
|---|---|---|
| aws:region | The AWS region to deploy into | us-west-2 |
pulumi config set:
pulumi config set aws:region <value>Press Enter to keep the default.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis the program: the code that declares your cloud resources.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis the program: the code that declares your cloud resources.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis the program: the code that declares your cloud resources.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis the program: the code that declares your cloud resources.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and holds the program: the resources it declares.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.
When setup completes, you’ll see a few key files:
Pulumi.yamlnames the project and the language it’s written in.Pulumi.dev.yamlholds thedevstack’s settings, including the values you just entered.index.tsindex.js__main__.pymain.goProgram.csProgram.fsProgram.vbApp.javaPulumi.yamlmain.tfis 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.
pulumi upPulumi 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:
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:
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.
The Lambda function’s code is function/handler.py. It’s Python whatever language the program is written in.
The Lambda function’s code is function/handler.py. It’s Python whatever language the program is written in.
The Lambda function’s code is function/handler.py. It’s Python whatever language the program is written in.
The Lambda function’s code is function/handler.py. It’s Python whatever language the program is written in.
The Lambda function’s code is function/handler.py. It’s Python whatever language the program is written in.
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(), };In function/handler.py:
def handler(event, context): return { 'statusCode': 200, 'body': datetime.now().isoformat() 'body': datetime.now().ctime() }In function/handler.py:
def handler(event, context): return { 'statusCode': 200, 'body': datetime.now().isoformat() 'body': datetime.now().ctime() }In function/handler.py:
def handler(event, context): return { 'statusCode': 200, 'body': datetime.now().isoformat() 'body': datetime.now().ctime() }In function/handler.py:
def handler(event, context): return { 'statusCode': 200, 'body': datetime.now().isoformat() 'body': datetime.now().ctime() }In function/handler.py:
def handler(event, context): return { 'statusCode': 200, 'body': datetime.now().isoformat() 'body': datetime.now().ctime() }Deploy the change and call /date again:
pulumi upcurl -s "$(pulumi stack output url)date"The time now comes back like Wed, 21 Oct 2026 14:05:09 GMT.
The time now comes back like Wed Oct 21 14:05:09 2026.
The time now comes back like Wed Oct 21 14:05:09 2026.
The time now comes back like Wed Oct 21 14:05:09 2026.
The time now comes back like Wed Oct 21 14:05:09 2026.
The time now comes back like Wed Oct 21 14:05:09 2026.
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:
pulumi destroyLearn more#
- Browse other architecture templates in the Templates gallery.
- Explore the AWS provider API docs in the Pulumi Registry.
- Walk through Pulumi from the ground up in Pulumi Tutorials.
- Read the latest serverless posts on the Pulumi blog.