DEV Community

Markus Siering
Markus Siering

Posted on

Solved: How to bundle Python apps within AWS CDK

Hi ๐Ÿ‘‹

๐Ÿ’ก Solution at the end ๐Ÿ™ˆ

So I've setup a basic TypeScript project with the AWS-CDK by running cdk init app --language=typescript. Now I'd like to use some lambda functions written in Python becauseโ€ฆ math ๐Ÿค“

I am using @aws-cdk/aws-lambda-python to declare these functions like so:

import * as cdk from "@aws-cdk/core"
import * as lambdaPython from "@aws-cdk/aws-lambda-python"

export class MyStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props)

    new lambdaPython.PythonFunction(this, "MyFunction", {
      entry: "lib/lambda/my_function",
    })
  }
}
Enter fullscreen mode Exit fullscreen mode

And within the lib/lambda/my_function folder, there is the index.py with a handler function which are both the defaults for the package.

But running cdk synth results in this:

$ cdk synth
[Status 1] stdout:


stderr: Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Enter fullscreen mode Exit fullscreen mode

I have no idea about how Docker needs to be setup. Unfortunately, I cannot find any info on this within the AWS documentation. Does anyone know what I'd have to do to get the (correct? ๐Ÿ˜…) Docker container running?

Solution

Use the latest Docker version, maybe? ๐Ÿ˜… I had a very old one (1.11.XX) running and now it works by installing the latest Docker Desktop (19.X.X) ๐Ÿคท

So overall: This is really nice, you can very easily mix TypeScript and Python in such a setup. Awesome! ๐Ÿš€ ๐Ÿ˜„

Top comments (0)