AWS CDK: Deploy AWS Lambda function

February 3rd, 2020

AWS Lambda functions are great. Using the AWS Cloud Development Kit in TypeScript, you can easily deploy files to AWS Lambda functions and configure an AWS Lambda Layer in the same CloudFormation Stack. After the deployment is done, the AWS Lambda function name to invoke the uploaded sources will be exposed as a CloudFormation Stack Output.

import path from 'path'

import * as CDK from '@aws-cdk/core'
import * as Lambda from '@aws-cdk/aws-lambda'

const filesLambda = path.resolve(__dirname, 'lambda')
const filesLayer = path.resolve(__dirname, 'layer')

export class LambdaStack extends CDK.Stack {
  constructor(app: CDK.App, id: string, props?: CDK.StackProps) {
    super(app, id, props)

    const layer = new LayerVersion(this, 'Layer, {
      compatibleRuntimes: [Runtime.NODEJS_12_X],
      code: Code.fromAsset(filesLayer)
    })

    const lambda = new Lambda.Function(this, 'Function', {
      code: Lambda.Code.fromAsset(filesLambda),
      handler: 'index.run',
      runtime: Lambda.Runtime.NODEJS_12_X,
      memorySize: 1024,
      timeout: CDK.Duration.seconds(3),
      layers: [layer]
    })

    new CDK.CfnOutput(this, 'FunctionName', {
      value: lambda.functionName
    })
  }
}

  • AWS CDK: Read data from AWS Parameter Store

    February 11th, 2020

    When you orchestrate an architecture von AWS, you’ll often end up with the need to read information like hostnames, identifiers, resource names or ARNs from somewhere for further processing. CloudFormation Stacks can have configured Outputs and Parameters, but using the AWS Parameter Store proved to…

  • AWS CDK: Store data in AWS Parameter Store

    February 11th, 2020

    When you orchestrate an architecture von AWS, you’ll often end up with the need to store information like hostnames, identifiers, resource names or ARNs somewhere for further processing. CloudFormation Stacks can have configured Outputs, but using the AWS Parameter Store proved to be a more flexible…

  • AWS CDK: Deploy static files to an Amazon S3 Bucket

    February 1st, 2020

    You can easily deploy static files stored in a folder to an Amazon S3 Bucket. If you configure your S3 Bucket for static website hosting, you can access all files via HTTPS from any browser or tool. Using the AWS Cloud Development Kit in TypeScript, your CloudFormation Stack can look like this…

  • Last Update: 2020-02-17T10:07:11.183Z
    Stresemannstraße 132, 22769 Hamburg
    +49 151 54 64 90 55
    inbox@sbstjn.com