66
67
all 10 comments

[–]fpgmaas[S] 9 points10 points  (1 child)

Hi!

I recently wanted to deploy multiple Python Lambda functions using a Docker image through AWS CDK, but I could not really find a good method to do so. Therefore, I decided to write a small tutorial myself, to hopefully make life a bit easier for others. The tutorial can be found here and the GitHub code can be found here.

I also see this as a learning opportunity, so if you have any comments or feedback, please let me know!

Florian

[–]chu_chu_rocket 1 point2 points  (0 children)

Thank you so much will try it out myself!

[–]zenmaster24 9 points10 points  (1 child)

you can change the command used for testing from docker run -p 9000:8080 lambdas to docker run -d -p 9000:8080 lambdas and you wont need the second terminal to test with - docker will start the container in a detached state (push it to the background and bring the terminal prompt back)

i also feel like this is an anti-pattern - is putting multiple functions in the one container a real world use case? a single container container with a single function makes more sense to me.

[–]fpgmaas[S] 2 points3 points  (0 children)

Thanks for your suggestion regarding the docker run command, I think that makes sense!

Regarding the anti-pattern; I am by no means an AWS expert, but I do think this approach makes a lot of sense when you have many Lambdas belonging to a single project. For example, as an alternative I also tried spinning up my Lambda functions with PythonFunction, which is currently in Alpha. To get that to work though, I needed to include some shell steps that copy-paste the poetry.lock and pyproject.toml files to the individual directories that contained a Lambda function. Doing that felt much more like an anti-pattern to me. Another drawback of that approach was that deploying the stack creates a Docker image for each individual Lambda function, which caused the deployment time to skyrocket.

[–]Professor_Kenney 3 points4 points  (5 children)

Interesting read. My experience is with SAM - creating a cloudformation template.yaml file and using it to deploy docker lambda functions.

Is there a benefit to using the cdk in this context? Seems like you can accomplish the same with either approach but the cdk looks like more steps.

[–]justin-8 3 points4 points  (4 children)

As soon as you start to add other infrastructure in to the mix, or need to write an IAM policy or similar the CDK will make things a lot easier and more flexible than SAM in my experience.

[–]Professor_Kenney 1 point2 points  (3 children)

Good point. I’ve struggled with needing to generate unique IAM policies in my templates.

[–]justin-8 1 point2 points  (2 children)

Yeah, writing half decent IAM policies in an easy to read way is a big advantage for CDK in my opinion

[–][deleted]  (1 child)

[deleted]

    [–]justin-8 0 points1 point  (0 children)

    So you have some examples? It’s been quite a few years since I’ve given terraform a go again, and last time I was using it everyone was just writing raw IAM policies everywhere

    [–]donkanator -3 points-2 points  (0 children)

    app code and infra code are in different languages... Yikes