forked from claranet/terraform-aws-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge w/ upstream master + claranet#36
- Loading branch information
Showing
15 changed files
with
171 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform 0.11.11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/bash | ||
# | ||
# Compiles a Python package into a zip deployable on AWS Lambda. | ||
# | ||
# - Builds Python dependencies into the package, using a Docker image to | ||
# correctly build native extensions | ||
# - Able to be used with the terraform-aws-lambda module | ||
# | ||
# Dependencies: | ||
# | ||
# - Docker | ||
# | ||
# Usage: | ||
# | ||
# $ ./build.sh <output-zip-filename> <runtime> <source-path> | ||
|
||
set -euo pipefail | ||
|
||
# Read variables from command line arguments | ||
FILENAME=$1 | ||
RUNTIME=$2 | ||
SOURCE_PATH=$3 | ||
|
||
# Convert to absolute paths | ||
SOURCE_DIR=$(cd "$SOURCE_PATH" && pwd) | ||
ZIP_DIR=$(cd "$(dirname "$FILENAME")" && pwd) | ||
ZIP_NAME=$(basename "$FILENAME") | ||
|
||
# Install dependencies, using a Docker image to correctly build native extensions | ||
docker run --rm -t -v "$SOURCE_DIR:/src" -v "$ZIP_DIR:/out" lambci/lambda:build-$RUNTIME sh -c " | ||
cp -r /src /build && | ||
cd /build && | ||
pip install --progress-bar off -r requirements.txt -t . && | ||
chmod -R 755 . && | ||
zip -r /out/$ZIP_NAME * && | ||
chown \$(stat -c '%u:%g' /out) /out/$ZIP_NAME | ||
" | ||
|
||
echo "Created $FILENAME from $SOURCE_PATH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def lambda_handler(event, context): | ||
print('importing numpy package') | ||
import numpy as np | ||
print('checking numpy works correctly') | ||
assert np.array_equal(np.array([1, 2]) + 3, np.array([4, 5])) | ||
return 'test passed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# numpy has native extensions, needs a custom build script to | ||
# install correctly if your host OS differs to Lambda OS | ||
numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
terraform { | ||
backend "local" { | ||
path = "terraform.tfstate" | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = "eu-west-1" | ||
} | ||
|
||
module "lambda" { | ||
source = "../../" | ||
|
||
function_name = "terraform-aws-lambda-test-build-command" | ||
description = "Test custom build command functionality in terraform-aws-lambda" | ||
handler = "main.lambda_handler" | ||
runtime = "python3.7" | ||
|
||
source_path = "${path.module}/lambda/src" | ||
|
||
build_command = "${path.module}/lambda/build.sh '$filename' '$runtime' '$source'" | ||
build_paths = ["${path.module}/lambda/build.sh"] | ||
} |
Oops, something went wrong.