Skip to main content

Deploying

This tutorial will show you how to deploy your Klotho compiled application. The following walkthrough references the ts-serverless-gateway application compiled with the name ts-sg, however, these steps will work with any Klotho compiled application.

note

This assumes you have already ran Klotho on your annotated application to generate the ./compiled directory. If not, please refer to our Your First Klotho App guide.

Deployment dependencies

Make sure you have installed and set up the following dependencies:

  • Ran Klotho on your application and generated the ./compiled folder
  • Docker
  • an AWS account, set up with either:
    • The AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY environment variables for a user
    • OR, $HOME/.aws/credentials (eg. via AWS CLI: aws configure) setup
  • Pulumi CLI
    • Follow the Pulumi installation instructions and set up for local usage:
      pulumi login --local
      export PULUMI_CONFIG_PASSPHRASE=""

Deploying with the CLI

From the root directory of your application, set the pulumi region configuration:

# region should be an aws region, for example us-west-1

pulumi config set aws:region <region> --cwd 'compiled/' -s ts-sg

If this is your first time deploying this application, you will be prompted to create the ts-sg stack. Just press ENTER and the stack will be created for you.

The stack 'ts-sg' does not exist.
If you would like to create this stack now, please press <ENTER>, otherwise press ^C:

Now that the Pulumi stack is created, simply install the project dependencies and deploy.

cd compiled
npm install
pulumi up

You'll see a preview of the changes to be applied to your AWS account: (you'll be able to delete these later on)

Previewing update (ts-sg):
Type Name Plan
+ pulumi:pulumi:Stack ts-sg-ts-sg create
+ ├─ awsx:ecr:Repository ts-sg create
+ │ └─ aws:ecr:LifecyclePolicy ts-sg create
+ ├─ aws:apigateway:RestApi app create
+ │ ├─ aws:apigateway:Method /-GET create
+ │ │ └─ aws:apigateway:Integration lambda-/-GET create
+ │ ├─ aws:apigateway:Resource v1 create
+ │ ├─ aws:apigateway:Resource users create
+ │ │ ├─ aws:apigateway:Method users-POST create
+ │ │ │ └─ aws:apigateway:Integration lambda-users-POST create
+ │ │ └─ aws:apigateway:Method users-GET create
+ │ │ └─ aws:apigateway:Integration lambda-users-GET create
+ │ ├─ aws:apigateway:Resource quote create
+ │ │ └─ aws:apigateway:Method quote-POST create
+ │ │ └─ aws:apigateway:Integration lambda-quote-POST create
+ │ ├─ aws:apigateway:Resource quote-list create
+ │ │ └─ aws:apigateway:Method quotelist-GET create
+ │ │ └─ aws:apigateway:Integration lambda-quotelist-GET create
+ │ └─ aws:apigateway:Deployment app-deployment create
+ │ └─ aws:apigateway:Stage app-stage create
+ ├─ aws:cloudwatch:LogGroup srvless-userget-function-api-lg create
+ ├─ aws:cloudwatch:LogGroup srvless-userpost-function-api-lg create
+ ├─ aws:s3:Bucket ts-sg-payloads create
+ ├─ aws:cloudwatch:LogGroup srvless-quotes-function-api-lg create
+ ├─ aws:ecr:Repository ts-sg create
+ ├─ aws:dynamodb:Table KV_ts-sg create
+ │ └─ aws:sqs:Queue ts-sg-kv-queue create
+ ├─ aws:iam:Role ts-sg_1231f_LambdaExec create
+ │ ├─ aws:iam:Policy ts-sg-srvless-quotes-exec create
+ │ └─ aws:iam:RolePolicyAttachment ts-sg-srvless-quotes-exec create
+ ├─ aws:iam:Role ts-sg_86e4e_LambdaExec create
+ │ ├─ aws:iam:Policy ts-sg-srvless-userget-exec create
+ │ └─ aws:iam:RolePolicyAttachment ts-sg-srvless-userget-exec create
+ ├─ aws:iam:Role ts-sg_bc115_LambdaExec create
+ │ ├─ aws:iam:Policy ts-sg-srvless-userpost-exec create
+ │ └─ aws:iam:RolePolicyAttachment ts-sg-srvless-userpost-exec create
+ ├─ aws:iam:RolePolicyAttachment ts-sg-srvless-userpost-lambdabasic create
+ ├─ aws:iam:RolePolicyAttachment ts-sg-srvless-userget-lambdabasic create
+ ├─ aws:iam:RolePolicyAttachment ts-sg-srvless-quotes-lambdabasic create
+ ├─ aws:lambda:Function srvless-userget create
+ ├─ aws:lambda:Function srvless-userpost create
+ ├─ aws:lambda:Function srvless-quotes create
+ ├─ aws:lambda:Permission post-v1users-permission create
+ ├─ aws:lambda:Permission get-v1users-permission create
+ ├─ aws:lambda:Permission get--permission create
+ ├─ aws:lambda:Permission get-v1quotelist-permission create
+ └─ aws:lambda:Permission post-v1quote-permission create

Resources:
+ 47 to create

Do you want to perform this update? [Use arrows to move, enter to select, type to filter]
> yes
no
details

Respond with yes when you're ready and wait for your resources to be created. This usually takes a couple minutes. When it's done deploying, you'll see the completion status and the AWS provided API Gateway URL for your API, assuming you are using @klotho::expose

Outputs:
apiUrls : [
[0]: "https://qxy99avspl.execute-api.us-east-1.amazonaws.com/stage/"
]

That's it! Your application is now deployed.

(Optional) Enabling web portal access for your deployment

caution

This behaviour is in alpha, and not released yet.

The Klotho web portal allows you to view information about your deploy, including topology images and console urls, in one centralizad location.

To enable this feature, make sure you have logged into klotho and validated your email.

klotho --login # if you haven't already

Then, simply set the pulumi config from within the ./compiled folder

cd ./compiled/
pulumi set config klo:webportal-upload true -s ts-sg
cd ..

Once the configuration value is set, you can go through the previous deployment section, and receive a web portal link, like the one below, once your deploy is complete:

Outputs:
apiUrls : [
[0]: "https://qxy99avspl.execute-api.us-east-1.amazonaws.com/stage/"
]
~ deploymentPortal: "https://app.klo.dev/dashboard/<name you specified at klotho compile>-3bccb27d-6276-4ef8-9169-5006ce5755ba"

Cleanup

When you're done with the environment, you can destroy the created resources with:

cd compiled
pulumi destroy -s ts-sg