Skip to content

Commit

Permalink
Fix permission of db index, S3 pull
Browse files Browse the repository at this point in the history
Tracked by #25 (comment)
  • Loading branch information
rivernews committed Sep 29, 2022
1 parent c24ba2d commit 233ce60
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cloud_module/pipeline/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module "step_function" {
module "scraper_lambda" {
source = "terraform-aws-modules/lambda/aws"
create_function = true
function_name = "${local.project_name}-scraper-lambda"
function_name = "${local.project_name}-landing-lambda"
description = "Lambda function for scraping"
handler = "landing"
runtime = "go1.x"
Expand Down
2 changes: 1 addition & 1 deletion cloud_module/pipeline/s3_triggers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module "landing_metadata_s3_trigger_lambda" {
source = "terraform-aws-modules/lambda/aws"

create_function = true
function_name = "${local.project_name}-fetch-stories"
function_name = "${local.project_name}-stories-lambda"
description = "Fetch ${local.project_name} stories; triggered by metadata.json creation"
handler = "stories"
runtime = "go1.x"
Expand Down
8 changes: 6 additions & 2 deletions cloud_module/pipeline/scheduler.tf
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ resource "aws_cloudwatch_event_target" "landing_metadata_scheduler_event_target"
module landing_metadata_cronjob_lambda {
source = "terraform-aws-modules/lambda/aws"
create_function = true
function_name = "${local.project_name}-batch-stories-fetch-parse"
function_name = "${local.project_name}-landing-metadata-cronjob-lambda"
description = "Query landing pages in db; compute & archive their metadata"
handler = "landing_metadata_cronjob"
runtime = "go1.x"
Expand All @@ -107,11 +107,15 @@ module landing_metadata_cronjob_lambda {
"dynamodb:Query",
"dynamodb:UpdateItem",
],
resources = [local.media_table_arn]
resources = [
local.media_table_arn,
"${local.media_table_arn}/index/metadataIndex"
]
}
s3_archive_bucket = {
effect = "Allow",
actions = [
"s3:GetObject",
"s3:PutObject",
],
resources = [
Expand Down
7 changes: 5 additions & 2 deletions cloud_module/pipeline/stories_sfn.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module batch_stories_sfn {
module fetch_story_lambda {
source = "terraform-aws-modules/lambda/aws"
create_function = true
function_name = "${local.project_name}-fetch-story"
function_name = "${local.project_name}-story-lambda"
description = "Fetch and archive a story page"
handler = "story"
runtime = "go1.x"
Expand Down Expand Up @@ -110,7 +110,10 @@ module "stories_finalizer_lambda" {
"dynamodb:Query",
"dynamodb:UpdateItem",
],
resources = [local.media_table_arn]
resources = [
local.media_table_arn,
"${local.media_table_arn}/index/s3KeyIndex"
]
}
}

Expand Down
6 changes: 3 additions & 3 deletions lambda_golang/cmd/landing_metadata_cronjob/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ type LambdaResponse struct {
Message string `json:"message:"`
}

func HandleRequest(ctx context.Context, s3Event events.S3Event) (LambdaResponse, error) {
items := newssite.DynamoDBQueryWaitingMetadata(ctx, newssite.DOCTYPE_LANDING)

func HandleRequest(ctx context.Context, cronjobEvent events.CloudWatchEvent) (LambdaResponse, error) {
GoTools.Logger("INFO", "Landing page metadata.json generator launched")

items := newssite.DynamoDBQueryWaitingMetadata(ctx, newssite.DOCTYPE_LANDING)

for _, landingItem := range *items {
landingPageS3Key := landingItem.S3Key
GoTools.Logger("INFO", fmt.Sprintf("Captured landing page at %s", landingPageS3Key))
Expand Down

0 comments on commit 233ce60

Please sign in to comment.