|
1 |
| -module "stories_queue" { |
2 |
| - source = "terraform-aws-modules/sqs/aws" |
3 |
| - version = ">= 2.0, < 3.0" |
4 |
| - |
5 |
| - # SQS queue attributes: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_CreateQueue.html |
6 |
| - |
7 |
| - # FIFO queue should append suffix .fifo |
8 |
| - name = "${local.project_name}-stories-queue" |
9 |
| - |
10 |
| - delay_seconds = 0 |
11 |
| - |
12 |
| - # so we can use per-message delay |
13 |
| - fifo_queue = false |
14 |
| - |
15 |
| - # FIFO queue only |
16 |
| - # content_based_deduplication = true |
17 |
| - |
18 |
| - visibility_timeout_seconds = 3600 |
| 1 | +resource "aws_s3_bucket_notification" "bucket_notification" { |
| 2 | + bucket = data.aws_s3_bucket.archive.id |
| 3 | + |
| 4 | + lambda_function { |
| 5 | + lambda_function_arn = module.landing_metadata_s3_trigger_lambda.lambda_function_arn |
| 6 | + events = ["s3:ObjectCreated:*"] |
| 7 | + filter_prefix = "${local.newssite_economy_alias}/" |
| 8 | + filter_suffix = "/metadata.json" |
| 9 | + } |
19 | 10 |
|
20 |
| - # enable long polling |
21 |
| - receive_wait_time_seconds = 10 |
| 11 | + depends_on = [ |
| 12 | + aws_lambda_permission.allow_bucket_trigger_by_landing_metadata |
| 13 | + ] |
| 14 | +} |
22 | 15 |
|
23 |
| - tags = { |
24 |
| - Project = local.project_name |
25 |
| - } |
| 16 | +resource "aws_lambda_permission" "allow_bucket_trigger_by_landing_metadata" { |
| 17 | + statement_id = "AllowExecutionFromS3Bucket" |
| 18 | + action = "lambda:InvokeFunction" |
| 19 | + function_name = module.landing_metadata_s3_trigger_lambda.lambda_function_arn |
| 20 | + principal = "s3.amazonaws.com" |
| 21 | + source_arn = data.aws_s3_bucket.archive.arn |
26 | 22 | }
|
27 | 23 |
|
28 |
| -module "stories_queue_consumer_lambda" { |
| 24 | +module "landing_metadata_s3_trigger_lambda" { |
29 | 25 | source = "terraform-aws-modules/lambda/aws"
|
30 | 26 |
|
31 | 27 | create_function = true
|
32 |
| - function_name = "${local.project_name}-fetch-stories" |
| 28 | + function_name = "${local.project_name}-stories-lambda" |
33 | 29 | description = "Fetch ${local.project_name} stories; triggered by metadata.json creation"
|
34 | 30 | handler = "stories"
|
35 | 31 | runtime = "go1.x"
|
@@ -62,30 +58,20 @@ module "stories_queue_consumer_lambda" {
|
62 | 58 | }
|
63 | 59 | EOF
|
64 | 60 |
|
65 |
| - # event source mapping for long polling |
66 |
| - event_source_mapping = { |
67 |
| - sqs = { |
68 |
| - event_source_arn = module.stories_queue.this_sqs_queue_arn |
69 |
| - batch_size = 1 |
70 |
| - } |
71 |
| - } |
72 |
| - allowed_triggers = { |
73 |
| - sqs = { |
74 |
| - principal = "sqs.amazonaws.com" |
75 |
| - source_arn = module.stories_queue.this_sqs_queue_arn |
76 |
| - } |
77 |
| - } |
78 | 61 | attach_policy_statements = true
|
79 | 62 | policy_statements = {
|
80 |
| - pull_sqs = { |
| 63 | + allow_db_put = { |
81 | 64 | effect = "Allow",
|
82 |
| - actions = ["sqs:ReceiveMessage", "sqs:DeleteMessage", "sqs:GetQueueAttributes"], |
83 |
| - resources = [module.stories_queue.this_sqs_queue_arn] |
| 65 | + actions = [ |
| 66 | + "dynamodb:UpdateItem", |
| 67 | + ], |
| 68 | + resources = [ |
| 69 | + local.media_table_arn, |
| 70 | + ] |
84 | 71 | }
|
85 | 72 | s3_archive_bucket = {
|
86 | 73 | effect = "Allow",
|
87 | 74 | actions = [
|
88 |
| - "s3:PutObject", |
89 | 75 | "s3:GetObject"
|
90 | 76 | ],
|
91 | 77 | resources = [
|
|
107 | 93 | SLACK_WEBHOOK_URL = var.slack_post_webhook_url
|
108 | 94 | LOGLEVEL = "DEBUG"
|
109 | 95 | ENV = local.environment
|
| 96 | + DEBUG = "true" |
110 | 97 |
|
111 | 98 | S3_ARCHIVE_BUCKET = data.aws_s3_bucket.archive.id
|
| 99 | + DYNAMODB_TABLE_ID = local.media_table_id |
112 | 100 | SFN_ARN = module.batch_stories_sfn.state_machine_arn
|
113 | 101 | }
|
114 | 102 |
|
|
0 commit comments