Social image generator - Part 1 Setup

Published on October 4th, 2019

Updated on October 24th, 2019 - Changelog

lambda icon

Before jumping into program solving and coding I have to set up environment. This includes serverless config, typescript and similar.

Yarn

For managing packages I chose to use Yarn, without any special configuration.

yarn init -y

For TypeScript support, I’ll need serverless-plugin-typescript and typescript as dev dependencies.

yarn add -D serverless-plugin-typescript typescript

Serverless Framework

Serverless framework will help manage AWS resources. Much better than zipping and uploading code to Lambda Dashboard on every change.

# serverless.yml

service: social-images

plugins:
  - serverless-plugin-typescript

provider:
  name: aws
  runtime: nodejs8.10
  stage: dev
  region: us-east-1

functions:
  generate:
    handler: handler.handler
    events:
      - http:
          path: /
          method: GET

TypeScript

Just the most basic configuration I found in serverless plugin docs.

//  tsconfig.json

{
  "compilerOptions": {
    "preserveConstEnums": true,
    "strictNullChecks": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "allowJs": true,
    "target": "es5",
    "outDir": ".build",
    "moduleResolution": "node",
    "lib": ["es2015"],
    "rootDir": "./"
  }
}

Handler

Last thing for today will be function handler. It won’t do anything for now.

// handler.ts

export const handler = async event => {
  return {
    statusCode: 200,
    body: 'hey',
  }
}

Changelog

  • October 24th, 2019 - renamed