1
1
resource "aws_s3_bucket_notification" "bucket_notification" {
2
2
bucket = data. aws_s3_bucket . archive . id
3
3
4
- lambda_function {
5
- lambda_function_arn = module. landing_s3_trigger_lambda . lambda_function_arn
6
- events = [" s3:ObjectCreated:*" ]
7
- filter_prefix = " ${ local . newssite_economy_alias } /"
8
- filter_suffix = " landing.html"
9
- }
10
-
11
4
lambda_function {
12
5
lambda_function_arn = module. landing_metadata_s3_trigger_lambda . lambda_function_arn
13
6
events = [" s3:ObjectCreated:*" ]
@@ -16,19 +9,10 @@ resource "aws_s3_bucket_notification" "bucket_notification" {
16
9
}
17
10
18
11
depends_on = [
19
- aws_lambda_permission . allow_bucket_trigger_by_landing ,
20
12
aws_lambda_permission . allow_bucket_trigger_by_landing_metadata
21
13
]
22
14
}
23
15
24
- resource "aws_lambda_permission" "allow_bucket_trigger_by_landing" {
25
- statement_id = " AllowExecutionFromS3Bucket"
26
- action = " lambda:InvokeFunction"
27
- function_name = module. landing_s3_trigger_lambda . lambda_function_arn
28
- principal = " s3.amazonaws.com"
29
- source_arn = data. aws_s3_bucket . archive . arn
30
- }
31
-
32
16
resource "aws_lambda_permission" "allow_bucket_trigger_by_landing_metadata" {
33
17
statement_id = " AllowExecutionFromS3Bucket"
34
18
action = " lambda:InvokeFunction"
@@ -37,52 +21,11 @@ resource "aws_lambda_permission" "allow_bucket_trigger_by_landing_metadata" {
37
21
source_arn = data. aws_s3_bucket . archive . arn
38
22
}
39
23
40
- module "landing_s3_trigger_lambda" {
41
- source = " terraform-aws-modules/lambda/aws"
42
- create_function = true
43
- function_name = " ${ local . project_name } -landing-s3-trigger-lambda"
44
- description = " Put a landing page in db"
45
- handler = " landing_s3_trigger"
46
- runtime = " go1.x"
47
-
48
- source_path = [{
49
- path = " ${ var . repo_dir } /lambda_golang/"
50
- commands = [" ${ local . go_build_flags } go build ./cmd/landing_s3_trigger" , " :zip" ]
51
- patterns = [" landing_s3_trigger" ]
52
- }]
53
-
54
- timeout = 900
55
- cloudwatch_logs_retention_in_days = 7
56
- publish = true
57
-
58
- attach_policy_statements = true
59
- policy_statements = {
60
- allow_db_put = {
61
- effect = " Allow" ,
62
- actions = [
63
- " dynamodb:PutItem" ,
64
- ],
65
- resources = [media_table_arn]
66
- }
67
- }
68
-
69
- environment_variables = {
70
- SLACK_WEBHOOK_URL = var.slack_post_webhook_url
71
- LOG_LEVEL = " DEBUG"
72
- DEBUG = " true"
73
- DYNAMODB_TABLE_ID = media_table_id
74
- }
75
-
76
- tags = {
77
- Project = local.project_name
78
- }
79
- }
80
-
81
24
module "landing_metadata_s3_trigger_lambda" {
82
25
source = " terraform-aws-modules/lambda/aws"
83
26
84
27
create_function = true
85
- function_name = " ${ local . project_name } -fetch- stories"
28
+ function_name = " ${ local . project_name } -stories-lambda "
86
29
description = " Fetch ${ local . project_name } stories; triggered by metadata.json creation"
87
30
handler = " stories"
88
31
runtime = " go1.x"
117
60
118
61
attach_policy_statements = true
119
62
policy_statements = {
63
+ allow_db_put = {
64
+ effect = " Allow" ,
65
+ actions = [
66
+ " dynamodb:UpdateItem" ,
67
+ ],
68
+ resources = [
69
+ local.media_table_arn,
70
+ ]
71
+ }
120
72
s3_archive_bucket = {
121
73
effect = " Allow" ,
122
74
actions = [
141
93
SLACK_WEBHOOK_URL = var.slack_post_webhook_url
142
94
LOGLEVEL = " DEBUG"
143
95
ENV = local.environment
96
+ DEBUG = " true"
144
97
145
98
S3_ARCHIVE_BUCKET = data.aws_s3_bucket.archive.id
99
+ DYNAMODB_TABLE_ID = local.media_table_id
146
100
SFN_ARN = module.batch_stories_sfn.state_machine_arn
147
101
}
148
102
0 commit comments