Skip to content

Commit 588494c

Browse files
committed
Deploy Lambda artifact from S3 bucket
Pull the deployment artifact from S3 using the new terraform-external-module-artifact module. This approach has the benefit of not checking in zip files into git, but the downside of more preamble when wanting to test this module as per the example docs. You need to know that the function should already be in S3 at a pre determined path. We need to think of proper deployment and promotion of these artifacts through different S3 buckets e.g. artifacts.testing.cloudposse.org -> artifacts.prod.cloudposse.org
1 parent 246f29b commit 588494c

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
**/.build-harness
1515
**/build-harness
1616
**/venv
17+
18+
*.zip

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ addons:
55
- make
66
- curl
77

8+
env:
9+
global:
10+
- TERRAFORM_MODULE_NAME="$(basename $TRAVIS_REPO_SLUG)"
11+
812
install:
913
- make init
1014

@@ -14,3 +18,17 @@ script:
1418
- make terraform/get-modules
1519
- make terraform/lint
1620
- make terraform/validate
21+
- make build
22+
23+
deploy:
24+
# Deploy artifacts to S3
25+
- provider: s3
26+
region: "us-west-2"
27+
access_key_id: $AWS_ACCESS_KEY_ID
28+
secret_access_key: $AWS_SECRET_ACCESS_KEY
29+
bucket: artifacts.prod.cloudposse.org
30+
skip_cleanup: true
31+
upload-dir: $TERRAFORM_MODULE_NAME/$TRAVIS_COMMIT
32+
local-dir: artifacts
33+
on:
34+
all_branches: true

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ dependencies:
2727
## Build Lambda function zip
2828
build: dependencies
2929
@echo "==> Building Lambda function zip..."
30-
@cd $(LAMBDA_DIR) && zip -r ../elasticsearch_cleanup.zip * && cd ../
30+
@mkdir -p artifacts
31+
@cd $(LAMBDA_DIR) && zip -r ../artifacts/lambda.zip * && cd ../

elasticsearch_cleanup.zip

-13.6 MB
Binary file not shown.

main.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ module "label" {
7272
enabled = "true"
7373
}
7474

75+
module "artifact" {
76+
source = "git::https://github.com/cloudposse/terraform-external-module-artifact.git?ref=tags/0.1.1"
77+
filename = "lambda.zip"
78+
module_name = "terraform-aws-lambda-elasticsearch-cleanup"
79+
module_path = "${path.module}"
80+
}
81+
7582
# Locals
7683
#--------------------------------------------------------------
7784
locals {
@@ -88,7 +95,7 @@ resource "aws_lambda_function" "default" {
8895
runtime = "python${var.python_version}"
8996
role = "${aws_iam_role.default.arn}"
9097
handler = "es-cleanup.lambda_handler"
91-
source_code_hash = "${base64sha256(file(local.lambda_path))}"
98+
source_code_hash = "${module.artifact.base64sha256}"
9299
tags = "${module.label.tags}"
93100

94101
environment {

0 commit comments

Comments
 (0)