|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +. ../demo-magic/demo-magic.sh |
| 4 | + |
| 5 | +# Clean up the account |
| 6 | + |
| 7 | +AWS_ACCOUNT_ID=`aws sts get-caller-identity --query 'Account' --output text` |
| 8 | + |
| 9 | +aws lambda delete-function --region us-east-1 --function-name php-example-hello |
| 10 | + |
| 11 | +for layerName in $(aws lambda list-layers --region us-east-1 | jq -r '.Layers[] | select(.LayerName | contains("img2lambda")) | .LayerName'); do |
| 12 | + for version in $(aws lambda list-layer-versions --region us-east-1 --layer-name "$layerName" | jq -r '.LayerVersions[].Version'); do |
| 13 | + aws lambda delete-layer-version --region us-east-1 --layer-name "$layerName" --version-number "$version" 1>&2 |
| 14 | + done |
| 15 | +done |
| 16 | + |
| 17 | +cd example/ |
| 18 | + |
| 19 | +clear |
| 20 | + |
| 21 | +# Look and feel |
| 22 | + |
| 23 | +TYPE_SPEED=15 |
| 24 | +DEMO_COMMENT_COLOR=$CYAN |
| 25 | +NO_WAIT=false |
| 26 | + |
| 27 | +# Start the demo |
| 28 | + |
| 29 | +PROMPT_TIMEOUT=0 |
| 30 | + |
| 31 | +p "# Welcome to img2lambda!" |
| 32 | + |
| 33 | +PROMPT_TIMEOUT=1 |
| 34 | + |
| 35 | +p "# Let's create a custom PHP runtime and a PHP function for AWS Lambda using Docker" |
| 36 | + |
| 37 | +pe "less Dockerfile" |
| 38 | + |
| 39 | +pe "docker build -t lambda-php ." |
| 40 | + |
| 41 | +p "# Love that fast Docker build caching!" |
| 42 | + |
| 43 | +p "# Let's test our PHP runtime and function locally with Docker" |
| 44 | + |
| 45 | +pe "docker run lambda-php hello '{\"name\": \"World\"}'" |
| 46 | + |
| 47 | +p "# img2lambda will extract our PHP function from the Docker image, and zip the files into a Lambda deployment package" |
| 48 | + |
| 49 | +p "# img2lambda will also extract our PHP runtime from the Docker image as Lambda layers, and publish the layers to Lambda" |
| 50 | + |
| 51 | +pe "img2lambda -i lambda-php:latest -r us-east-1 -o ./output" |
| 52 | + |
| 53 | +p "# img2lambda found our PHP function files in the Docker image and zipped them up" |
| 54 | + |
| 55 | +pe "unzip -l output/function.zip" |
| 56 | + |
| 57 | +p "# img2lambda also found 2 layers in the Docker image that contain our PHP runtime files, so it created 2 Lambda layers and published them" |
| 58 | + |
| 59 | +pe "more output/layers.json" |
| 60 | + |
| 61 | +p "# Now we can create a Lambda function that uses the deployment package and the published layers" |
| 62 | + |
| 63 | +TYPE_SPEED='' |
| 64 | +pe "aws lambda create-function --function-name php-example-hello --zip-file fileb://./output/function.zip --layers file://./output/layers.json --runtime provided --handler hello --role \"arn:aws:iam::$AWS_ACCOUNT_ID:role/service-role/LambdaPhpExample\" --region us-east-1" |
| 65 | +TYPE_SPEED=15 |
| 66 | + |
| 67 | +p "# Let's now invoke the function and test out our PHP custom runtime" |
| 68 | + |
| 69 | +TYPE_SPEED='' |
| 70 | +pe "aws lambda invoke --function-name php-example-hello --payload '{\"name\": \"World\"}' --region us-east-1 --log-type Tail --query 'LogResult' --output text hello-output.txt | base64 --decode" |
| 71 | +TYPE_SPEED=15 |
| 72 | + |
| 73 | +pe "more hello-output.txt" |
| 74 | + |
| 75 | +p "# Enjoy building your Lambda functions and layers with Docker and img2lambda!" |
0 commit comments