No description or website provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Typescript app deployment against AWS EB

To deploy an app built with Typescript, we have to deploy its artifacts rather than source code managed by git.

0 - Install EB CLI

To manipulate Elasticbeanstalk, we need to use EB CLI, written in Python. We install this with PIP.

pip install awsebcli --upgrade --user

If you don't have Python, you can download from Any version above v2.7 or v3.4 should work.

Also, you have to install pip. Check this link too.

1 - Prepare package


# Generate package.json
npm init -y

# Install dependencies
npm i -D typescript @types/node @types/express
npm i express


  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "rootDir": "src",
    "outDir": "build"

2 - Create App


import express = require('express')

const app = express()

app.use((req, res) => {

app.listen(process.env.PORT, () => {
  console.log('server is ready.')

3 - Build typescript and check

Add build and start scripts to package.json.

  "scripts": {
    "build": "tsc",
    "start": "node build/index.js"

Compile and run our app with the scripts

# Compile typescript
npm run build

# Run with compiled javascript
PORT=3000 npm run start

Check our app actually working at http://localhost:3000

4 - Prepare Artifact


# If the directory, `dist`, doesn't exist, create `dist`
stat dist || mkdir dist
# Archive artifacts
zip dist/$ -r build package.json package-lock.json

Add dist script

  "scripts": {
    "build": "tsc",
    "start": "node build/index.js",
    "dist": "sh ./scripts/"

5 - Deploy app

# Initialize app to EB
eb init

# Initialize environment
eb create

Add the below 2 lines to the bottom of .elasticbeanstalk/config.yml.

  artifact: dist/

Deploy again

eb deploy --staged