forked from facebook/ThreatExchange
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an EFS durable file system for hashing lambda (facebook#933)
* Add an EFS durable file system for hashing lambda Summary --- This file system will be used to write content hashes by the hashing lambda so that we can build indexes to use for retroaction. Test Plan --- ``` $ terraform init $ terraform apply ``` Added the following snippet to the hashing lambda and deployed. ```python with open(f"/mnt/durable-storage/{context.aws_request_id}.file", "w") as f: f.write("Hello, World!") from os import listdir logger.info(listdir("/mnt/durable-storage/")) ``` Hit test a few times, deployed a new version of the lambda and then checked the logs.. Saw the following ``` [INFO] 2022-02-24T03:21:05.008Z 9e057c0d-2027-468a-b797-f261d3964178 ['944d7e76-0fb5-4a7b-9104-de86fd90dfc0.file', 'a36b2c1b-1ef4-47d0-aa5c-7f69498c12fd.file', '57e95dc9-efaa-4707-abac-ab1017c7c7ed.file', 'abff2ab6-fd19-47dd-85d8-3bcf2f63c5b7.file', '51191f91-75fc-4f6d-a770-44c46725c054.file', '9e057c0d-2027-468a-b797-f261d3964178.file'] ``` See how files accumulate in the file system. * Upgrade terraform version
- Loading branch information
Showing
7 changed files
with
144 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,59 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved | ||
|
||
data "aws_region" "current" {} | ||
|
||
/* | ||
* # Durable file system | ||
* Hashing labmda uses an elastic file-system to write hashes at a | ||
* high-througput. The files so-generated are used in other lambdas to create | ||
* clusters from recently seen content. | ||
* | ||
* EFS can only be mounted onto lambdas that are connected to a VPC. So, this | ||
* module ends up creating a dedicated VPC. | ||
*/ | ||
resource "aws_efs_file_system" "lcc_durable_fs" { | ||
creation_token = "${var.prefix}-lcc-durable-filesystem" | ||
|
||
tags = merge( | ||
var.additional_tags, | ||
{ | ||
Name = "LCC_DurableFS" | ||
} | ||
) | ||
} | ||
|
||
# Create a VPC for EFS mounts | ||
module "lcc_efs_vpc" { | ||
source = "terraform-aws-modules/vpc/aws" | ||
|
||
name = "${var.prefix}-lcc-efs-vpc" | ||
cidr = "10.10.0.0/16" | ||
azs = ["${data.aws_region.current.name}a", "${data.aws_region.current.name}b", "${data.aws_region.current.name}c"] | ||
intra_subnets = ["10.10.101.0/24"] | ||
} | ||
|
||
# Mount target connects the file system to the subnet | ||
resource "aws_efs_mount_target" "lcc_durable_fs" { | ||
file_system_id = aws_efs_file_system.lcc_durable_fs.id | ||
subnet_id = module.lcc_efs_vpc.intra_subnets[0] | ||
security_groups = [module.lcc_efs_vpc.default_security_group_id] | ||
} | ||
|
||
# EFS access point used by lambda file system | ||
resource "aws_efs_access_point" "access_point_for_lambda" { | ||
file_system_id = aws_efs_file_system.lcc_durable_fs.id | ||
|
||
root_directory { | ||
path = "/lambda" | ||
creation_info { | ||
owner_gid = 1000 | ||
owner_uid = 1000 | ||
permissions = "777" | ||
} | ||
} | ||
|
||
posix_user { | ||
gid = 1000 | ||
uid = 1000 | ||
} | ||
} |
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,12 @@ | ||
|
||
output "durable_fs_security_group_ids" { | ||
value = [module.lcc_efs_vpc.default_security_group_id] | ||
} | ||
|
||
output "durable_fs_subnet_ids" { | ||
value = module.lcc_efs_vpc.intra_subnets | ||
} | ||
|
||
output "durable_fs_arn" { | ||
value = aws_efs_access_point.access_point_for_lambda.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,11 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved | ||
|
||
variable "prefix" { | ||
description = "Prefix to use for resource names" | ||
type = string | ||
} | ||
|
||
variable "additional_tags" { | ||
description = "Additional resource tags" | ||
type = map(string) | ||
} |
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
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