This repository has been archived by the owner on Aug 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e20be39
commit 2c1ed28
Showing
10 changed files
with
115 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Example with S3 event | ||
|
||
Creates an AWS Lambda function triggered by a S3 [event](https://docs.aws.amazon.com/lambda/latest/dg/with-s3.html). | ||
|
||
## requirements | ||
|
||
- [Terraform 0.12+](https://www.terraform.io/) | ||
- authentication configuration for the [aws provider](https://www.terraform.io/docs/providers/aws/) | ||
|
||
## usage | ||
|
||
``` | ||
terraform init | ||
terraform plan | ||
``` |
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,38 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
} | ||
|
||
resource "aws_s3_bucket_notification" "bucket_notification" { | ||
bucket = "bucketname" | ||
|
||
lambda_function { | ||
lambda_function_arn = module.lambda.arn | ||
events = ["s3:ObjectCreated:*"] | ||
} | ||
} | ||
|
||
module "lambda" { | ||
source = "../../" | ||
description = "Example AWS Lambda using go with S3 trigger" | ||
filename = "${path.module}/test_function.zip" | ||
function_name = "tf-example-go-s3" | ||
handler = "example-lambda-func" | ||
runtime = "go1.x" | ||
|
||
event = { | ||
type = "s3" | ||
s3_bucket_arn = "arn:aws:s3:::bucketname" | ||
s3_bucket_id = "bucketname" | ||
} | ||
|
||
tags = { | ||
key = "value" | ||
} | ||
|
||
environment = { | ||
variables = { | ||
key = "value" | ||
} | ||
} | ||
} | ||
|
Empty file.
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,4 @@ | ||
|
||
terraform { | ||
required_version = ">= 0.12" | ||
} |
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,8 @@ | ||
resource "aws_lambda_permission" "allow_bucket" { | ||
count = var.enable ? 1 : 0 | ||
action = "lambda:InvokeFunction" | ||
function_name = var.lambda_function_arn | ||
principal = "s3.amazonaws.com" | ||
statement_id = "AllowExecutionFromS3Bucket" | ||
source_arn = var.s3_bucket_arn | ||
} |
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,34 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# REQUIRED PARAMETERS | ||
# You must provide a value for each of these parameters. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
variable "lambda_function_arn" { | ||
description = "The Amazon Resource Name (ARN) identifying the Lambda Function triggered by S3" | ||
} | ||
|
||
variable "s3_bucket_arn" { | ||
description = "The ARN of the bucket." | ||
} | ||
|
||
variable "s3_bucket_id" { | ||
description = "The name of the bucket." | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# OPTIONAL PARAMETERS | ||
# These parameters have reasonable defaults. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
variable "enable" { | ||
description = "Conditionally enables this module (and all it's ressources)." | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "lambda_function_notification" { | ||
description = "(multiple) Used to configure notifications to a Lambda Function. See https://www.terraform.io/docs/providers/aws/r/s3_bucket_notification.html#lambda_function for allowed values." | ||
type = list(map(string)) | ||
default = [] | ||
} | ||
|
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,4 @@ | ||
|
||
terraform { | ||
required_version = ">= 0.12" | ||
} |
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