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
# ... | |
resource "aws_sns_topic_subscription" "topic_lambda_sync_bucket_1" { | |
topic_arn = "${aws_sns_topic.s3_fanout.arn}" | |
protocol = "lambda" | |
endpoint = "${aws_lambda_function.source_to_target_1_sync.arn}" | |
} | |
resource "aws_sns_topic_subscription" "topic_lambda_sync_bucket_2" { | |
topic_arn = "${aws_sns_topic.s3_fanout.arn}" | |
protocol = "lambda" |
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
An execution plan has been generated and is shown below. | |
Resource actions are indicated with the following symbols: | |
+ create | |
<= read (data resources) | |
Terraform will perform the following actions: | |
<= data.aws_iam_policy_document.move_object | |
id: <computed> | |
json: <computed> |
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
# ... | |
resource "aws_lambda_permission" "with_sns_1" { | |
statement_id = "AllowExecutionFromSNS" | |
action = "lambda:InvokeFunction" | |
function_name = "${aws_lambda_function.source_to_target_1_sync.function_name}" | |
principal = "sns.amazonaws.com" | |
source_arn = "${aws_sns_topic.s3_fanout.arn}" | |
} | |
resource "aws_lambda_permission" "with_sns_2" { |
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
# The policy | |
data "aws_iam_policy_document" "move_object" { | |
statement { | |
effect = "Allow" | |
actions = [ | |
"logs:CreateLogGroup", | |
"logs:CreateLogStream", | |
"logs:PutLogEvents" | |
] | |
resources = [ |
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
resource "aws_lambda_function" "source_to_target_1_sync" { | |
function_name = "source_to_target_1_sync" | |
filename = "${data.archive_file.push_to_bucket_1.output_path}" | |
source_code_hash = "${data.archive_file.push_to_bucket_1.output_base64sha256}" | |
role = "${aws_iam_role.source_to_target_sync.arn}" | |
handler = "push_to_bucket_1.lambda_handler" | |
runtime = "python2.7" | |
} | |
resource "aws_lambda_function" "source_to_target_2_sync" { |
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
data "archive_file" "push_to_bucket_1" { | |
type = "zip" | |
source_file = "push_to_bucket_1.py" | |
output_path = "push_to_bucket_1.zip" | |
} | |
data "archive_file" "push_to_bucket_2" { | |
type = "zip" | |
source_file = "push_to_bucket_2.py" | |
output_path = "push_to_bucket_2.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
# ... | |
provider "archive" { | |
version = "~> 1.1" | |
} |
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 source code: | |
# aws.amazon.com/blogs/compute/content-replication-using-aws-lambda-and-amazon-s3/ | |
import urllib | |
import boto3 | |
import ast | |
import json | |
print('Loading function') | |
def lambda_handler(event, context): | |
s3 = boto3.client('s3') |
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 source code: | |
# aws.amazon.com/blogs/compute/content-replication-using-aws-lambda-and-amazon-s3/ | |
import urllib | |
import boto3 | |
import ast | |
import json | |
print('Loading function') | |
def lambda_handler(event, context): | |
s3 = boto3.client('s3') |
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
# ... | |
resource "aws_s3_bucket_notification" "object_create_sns" { | |
bucket = "${aws_s3_bucket.source-bucket.id}" | |
topic { | |
topic_arn = "${aws_sns_topic.s3_fanout.arn}" | |
events = ["s3:ObjectCreated:*"] | |
} | |
} |
NewerOlder