|
1 | 1 | ## AWS Lambda Container Image Converter
|
2 | 2 |
|
3 |
| -This container image converter tool (img2lambda) repackages container images (such as Docker images) into AWS Lambda layers, and publishes them as new layer versions. |
| 3 | +This container image converter tool (img2lambda) repackages container images (such as Docker images) into AWS Lambda layers, and publishes them as new layer versions to Lambda. The tool copies all files under '/opt' in the Docker image, maintaining the individual Docker image layers as individual Lambda layers. The published layer ARNs will be stored in a file 'output/layers.json', which can be used as input when creating Lambda functions. |
4 | 4 |
|
5 | 5 | ```
|
| 6 | +USAGE: |
| 7 | + img2lambda [options] |
| 8 | +
|
| 9 | +GLOBAL OPTIONS: |
| 10 | + --image value, -i value Name of the source container image. For example, 'my-docker-image:latest' |
| 11 | + --region value, -r value AWS region (default: "us-east-1") |
| 12 | + --output-directory value, -o value Destination directory for command output (default: "./output") |
| 13 | + --layer-namespace value, -n value Prefix for the layers published to Lambda (default: "img2lambda") |
| 14 | + --dry-run, -d Conduct a dry-run: Repackage the image, but only write the Lambda layers to local disk (do not publish to Lambda) |
| 15 | + --help, -h show help |
| 16 | +``` |
| 17 | + |
| 18 | +## Build |
| 19 | + |
| 20 | +``` |
| 21 | +go get -t -v ./... |
| 22 | +``` |
| 23 | + |
| 24 | +## Example |
| 25 | + |
| 26 | +Build the example Docker image to create a PHP Lambda custom runtime: |
| 27 | +``` |
| 28 | +cd example |
| 29 | +
|
6 | 30 | docker build -t lambda-php .
|
| 31 | +``` |
7 | 32 |
|
| 33 | +The example PHP functions are also built into the example image, so they can be run with Docker: |
| 34 | +``` |
8 | 35 | docker run lambda-php hello '{"name": "World"}'
|
9 | 36 |
|
10 | 37 | docker run lambda-php goodbye '{"name": "World"}'
|
| 38 | +``` |
| 39 | + |
| 40 | +Run the tool to create and publish Lambda layers that contain the PHP custom runtime: |
| 41 | +``` |
| 42 | +../../../bin/img2lambda -i lambda-php:latest -r us-east-1 |
| 43 | +``` |
| 44 | + |
| 45 | +Create a PHP function that uses the layers: |
| 46 | +``` |
| 47 | +cd function |
11 | 48 |
|
12 |
| -../../bin/img2lambda -i docker-daemon:lambda-php:latest |
| 49 | +zip hello.zip src/hello.php |
| 50 | +
|
| 51 | +aws lambda create-function \ |
| 52 | + --function-name php-example-hello \ |
| 53 | + --handler hello \ |
| 54 | + --zip-file fileb://./hello.zip \ |
| 55 | + --runtime provided \ |
| 56 | + --role "arn:aws:iam::XXXXXXXXXXXX:role/service-role/LambdaPhpExample" \ |
| 57 | + --region us-east-1 \ |
| 58 | + --layers file://../output/layers.json |
| 59 | +``` |
| 60 | + |
| 61 | +Finally, invoke the function: |
13 | 62 | ```
|
| 63 | +aws lambda invoke \ |
| 64 | + --function-name php-example-hello \ |
| 65 | + --region us-east-1 \ |
| 66 | + --log-type Tail \ |
| 67 | + --query 'LogResult' \ |
| 68 | + --output text \ |
| 69 | + --payload '{"name": "World"}' hello-output.txt | base64 --decode |
| 70 | +
|
| 71 | +cat hello-output.txt |
| 72 | +``` |
| 73 | + |
| 74 | +## TODO |
14 | 75 |
|
15 |
| -TODO: |
16 | 76 | * Support image types other than local Docker images, where the layer format is tar. For example, layers directly from a Docker registry will be .tar.gz-formatted. OCI images can be either tar or tar.gz, based on the layer's media type.
|
17 | 77 | * De-dupe Lambda layers before publishing them (compare local file's SHA256 to published layer versions with the same name)
|
18 | 78 | * Accept additional parameters for PublishLayerVersion API (license, description, etc)
|
19 | 79 | * Support Lambda compatible runtimes other than 'provided'
|
20 |
| -* Utility for creating a function deployment package from a Docker image |
| 80 | +* Utility for creating a function deployment package from a Docker image (copying from /var/task/src instead of /opt) |
21 | 81 |
|
22 | 82 | ## License Summary
|
23 | 83 |
|
|
0 commit comments