Skip to content

AWS Lambda to generate PlantUML diagrams via POST to its URL

License

Notifications You must be signed in to change notification settings

paulrobello/plantuml

Repository files navigation

Plant UML lambda url to generate UML diagrams in SVG format

Description

This projects builds a lambda layer containing the plantuml jar file and OpenJDK JRE to run the jar file, as well as graphviz to generate additional diagram types.
It then creates a pyton lambda that uses the layer to run the plantuml jar file to generate SVG diagrams from PlantUML text.
The lambda is invoked via POST to Function URL with uml in body, and requires an API key to be passed in the header.
The lambda and its layer are built for arm64 to reduce cost.
The lambda is also uses AWS hosted Lambda Powertools layer. Due to the memory required to run the java program, and to decrease execution time, the lambda is configured with 1024MB of memory.
Average time to return a diagram from warm lambda is 5 seconds and 9 seconds for cold.
The layer and the lambda are built using docker.
The makefile has all needed targets to build and deploy the solution using only aws cli.

Usage

Prerequisites

Create a .env file in the project root with the following keys for your deployment:

  • AWS_ACCT=You must specify your aws account number
  • AWS_REGION=Defaults to "us-east-1"
  • API_KEY=Any key you want to use to secure the lambda. Defaults to "WootWootWoot"
  • LAMBDA_NAME=Defaults to "plantuml"
  • PLANTUML_VERSION=Defaults to "1.2024.3"
  • LAMBDA_POWER_TOOLS_LAYER_VERSION=Defaults to "69"

Note you must assume aws creds in target AWS_ACCT before running any make targets

Build and deploy 1st time

make deploy

Update Lambda and layer

make it-again

Make targets to test the lambda

These targets will create or overwrite the test-diagram.svg file with the diagram generated by the lambda.

make post-lambda-url
make post-lambda-url-c4
make post-lambda-url-aws
make post-lambda-url-icons

CURL example

Note replace the lambda url with the one output from the:

make deploy

or

make get-lambda-url.  

You must must also ensure the API key is correct. You can get the key with:

make get-lambda-env
curl -X POST https://2ysjlufldcjgubu3w7b3ts2pfy0vmfbn.lambda-url.us-east-1.on.aws/ \
	-H 'Content-Type: text/plain' \
	-H 'X-API-Key: WootWootWoot' \
	--data-binary @./test-diagram.puml > test-diagram.svg

Web

You can also use the web page to generate diagrams.
web/index.html allows you to specify your lambda url / api key and PUML diagram to generate the SVG.

About

AWS Lambda to generate PlantUML diagrams via POST to its URL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published