Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload files to s3 and reduce the memory and increase timeout #3935

Merged
merged 10 commits into from
Nov 9, 2023
8 changes: 5 additions & 3 deletions terraform/environments/apex/event_triggers.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
resource "aws_cloudwatch_event_rule" "snapshotDBFunctionmon_sun" {
name = "laa-createSnapshotRule-${local.application_name}-${local.environment}-mp"
description = "Daily snapshots of Oracle volumes"
schedule_expression = "cron(51 14 ? * MON-SUN *)"

name = "laa-createSnapshotRule-${local.application_name}-${local.environment}-mp"
description = "Daily snapshots of Oracle volumes"
schedule_expression = "cron(00 04 ? * MON-SUN *)"


}
resource "aws_lambda_permission" "allow_cloudwatch_to_call_check_mon_sun" {
Expand Down
81 changes: 57 additions & 24 deletions terraform/environments/apex/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ module "s3_bucket_lambda" {

}

resource "aws_s3_object" "provision_files" {
bucket = "laa-${local.application_name}-${local.environment}-mp"
for_each = fileset("./zipfiles/", "**")
key = each.value
source = "./zipfiles/${each.value}"
content_type = each.value
}


resource "time_sleep" "wait_for_provision_files" {
create_duration = "200s"
depends_on = [ aws_s3_object.provision_files ]
}

resource "aws_security_group" "lambdasg" {
name = "${local.application_name}-${local.environment}-lambda-security-group"
description = "APEX Lambda Security Group"
Expand All @@ -42,6 +56,7 @@ data "archive_file" "deletesnapshot_file" {
type = "zip"
source_file = local.deletesnapshot_source_file
output_path = local.deletesnapshot_output_path

}

data "archive_file" "dbconnect_file" {
Expand All @@ -64,16 +79,21 @@ resource "aws_lambda_layer_version" "lambda_layer" {


resource "aws_lambda_function" "snapshotDBFunction" {
function_name = local.snapshotDBFunctionname
role = module.iambackup.backuprole
handler = local.snapshotDBFunctionhandler

description = "Snapshot volumes for Oracle EC2"
function_name = local.snapshotDBFunctionname
role = module.iambackup.backuprole
handler = local.snapshotDBFunctionhandler
source_code_hash = data.archive_file.dbsnapshot_file.output_base64sha256
runtime = local.snapshotDBFunctionruntime
layers = [aws_lambda_layer_version.lambda_layer.arn]
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.snapshotDBFunctionfilename
memory_size = 350
timeout = 300
runtime = local.snapshotDBFunctionruntime
layers = [aws_lambda_layer_version.lambda_layer.arn]
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.snapshotDBFunctionfilename
memory_size = 128
timeout = 900
depends_on = [ time_sleep.wait_for_provision_files ]




environment {
Expand All @@ -93,13 +113,19 @@ resource "aws_lambda_function" "snapshotDBFunction" {
}

resource "aws_lambda_function" "deletesnapshotFunction" {
function_name = local.deletesnapshotFunctionname
role = module.iambackup.backuprole
handler = local.deletesnapshotFunctionhandler

description = "Clean up script to delete old unused snapshots"
function_name = local.deletesnapshotFunctionname
role = module.iambackup.backuprole
handler = local.deletesnapshotFunctionhandler
source_code_hash = data.archive_file.deletesnapshot_file.output_base64sha256
runtime = local.deletesnapshotFunctionruntime
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.deletesnapshotFunctionfilename
runtime = local.deletesnapshotFunctionruntime
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.deletesnapshotFunctionfilename
memory_size = 1024
timeout = 900
depends_on = [ time_sleep.wait_for_provision_files ]


environment {
variables = {
Expand All @@ -119,16 +145,21 @@ resource "aws_lambda_function" "deletesnapshotFunction" {


resource "aws_lambda_function" "connectDBFunction" {
function_name = local.connectDBFunctionname
role = module.iambackup.backuprole
handler = local.connectDBFunctionhandler

description = "SSH to the DB EC2"
function_name = local.connectDBFunctionname
role = module.iambackup.backuprole
handler = local.connectDBFunctionhandler
source_code_hash = data.archive_file.dbconnect_file.output_base64sha256
runtime = local.connectDBFunctionruntime
layers = [aws_lambda_layer_version.lambda_layer.arn]
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.connectDBFunctionfilename
memory_size = 350
timeout = 300
runtime = local.connectDBFunctionruntime
layers = [aws_lambda_layer_version.lambda_layer.arn]
s3_bucket = module.s3_bucket_lambda.lambdabucketname
s3_key = local.connectDBFunctionfilename
memory_size = 128
timeout = 900
depends_on = [ time_sleep.wait_for_provision_files ]



environment {
variables = {
Expand All @@ -146,3 +177,5 @@ resource "aws_lambda_function" "connectDBFunction" {
)
}



12 changes: 12 additions & 0 deletions terraform/environments/apex/modules/s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ resource "aws_s3_bucket" "laa-lambda-backup" {
tags = var.tags
}


resource "aws_s3_object" "provision_files" {
bucket = aws_s3_bucket.laa-lambda-backup.id
for_each = fileset("./zipfiles/", "**")
key = each.value
source = "./zipfiles/${each.value}"
content_type = each.value
}




resource "aws_s3_bucket_ownership_controls" "default" {
bucket = aws_s3_bucket.laa-lambda-backup.id
rule {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added terraform/environments/apex/zipfiles/nodejs.zip
Binary file not shown.
Loading