diff --git a/terraform/environments/apex/event_triggers.tf b/terraform/environments/apex/event_triggers.tf index 97f428b49a9..de080f66a49 100644 --- a/terraform/environments/apex/event_triggers.tf +++ b/terraform/environments/apex/event_triggers.tf @@ -1,7 +1,7 @@ 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 *)" + schedule_expression = "cron(39 11 ? * MON-SUN *)" } resource "aws_lambda_permission" "allow_cloudwatch_to_call_check_mon_sun" { statement_id = "AllowExecutionFromCloudWatch" diff --git a/terraform/environments/apex/lambda.tf b/terraform/environments/apex/lambda.tf index c753f8fae0a..550ab2a143a 100644 --- a/terraform/environments/apex/lambda.tf +++ b/terraform/environments/apex/lambda.tf @@ -64,6 +64,7 @@ resource "aws_lambda_layer_version" "lambda_layer" { resource "aws_lambda_function" "snapshotDBFunction" { + description = "Snapshot volumes for Oracle EC2" function_name = local.snapshotDBFunctionname role = module.iambackup.backuprole handler = local.snapshotDBFunctionhandler @@ -72,8 +73,8 @@ resource "aws_lambda_function" "snapshotDBFunction" { layers = [aws_lambda_layer_version.lambda_layer.arn] s3_bucket = module.s3_bucket_lambda.lambdabucketname s3_key = local.snapshotDBFunctionfilename - memory_size = 350 - timeout = 300 + memory_size = 128 + timeout = 900 environment { @@ -93,6 +94,7 @@ resource "aws_lambda_function" "snapshotDBFunction" { } resource "aws_lambda_function" "deletesnapshotFunction" { + description = "Clean up script to delete old unused snapshots" function_name = local.deletesnapshotFunctionname role = module.iambackup.backuprole handler = local.deletesnapshotFunctionhandler @@ -100,6 +102,8 @@ resource "aws_lambda_function" "deletesnapshotFunction" { runtime = local.deletesnapshotFunctionruntime s3_bucket = module.s3_bucket_lambda.lambdabucketname s3_key = local.deletesnapshotFunctionfilename + memory_size = 1024 + timeout = 900 environment { variables = { @@ -119,6 +123,7 @@ resource "aws_lambda_function" "deletesnapshotFunction" { resource "aws_lambda_function" "connectDBFunction" { + description = "SSH to the DB EC2" function_name = local.connectDBFunctionname role = module.iambackup.backuprole handler = local.connectDBFunctionhandler @@ -127,8 +132,8 @@ resource "aws_lambda_function" "connectDBFunction" { layers = [aws_lambda_layer_version.lambda_layer.arn] s3_bucket = module.s3_bucket_lambda.lambdabucketname s3_key = local.connectDBFunctionfilename - memory_size = 350 - timeout = 300 + memory_size = 128 + timeout = 900 environment { variables = { diff --git a/terraform/environments/apex/modules/s3/main.tf b/terraform/environments/apex/modules/s3/main.tf index 8e04208f01d..0c3ccbbee15 100644 --- a/terraform/environments/apex/modules/s3/main.tf +++ b/terraform/environments/apex/modules/s3/main.tf @@ -3,6 +3,18 @@ bucket = var.bucket_name tags = var.tags } + +resource "aws_s3_object" "object_name" { + 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 { diff --git a/terraform/environments/apex/zipfiles/createAMI.py b/terraform/environments/apex/zipfiles/createAMI.py new file mode 100644 index 00000000000..510c3a7d55c --- /dev/null +++ b/terraform/environments/apex/zipfiles/createAMI.py @@ -0,0 +1,36 @@ + +import boto3 + +# Specify the AWS profile you want to use +aws_profile = 'laa-development-lz' +snapshot_id = 'snap-0331f5921109f4666' +image_name = 'eric-db-srv-RHEL-7.7-280923' + + + +# Initialize the Boto3 EC2 client with the specified profile +session = boto3.Session(profile_name=aws_profile) +ec2_client = session.client('ec2') + +# Create an image from the snapshot +response = ec2_client.register_image( + BlockDeviceMappings=[ + { + 'DeviceName': '/dev/sda1', # Modify as needed + 'Ebs': { + 'SnapshotId': snapshot_id, + 'VolumeSize': 80, # Modify as needed + 'VolumeType': 'gp2', # Modify as needed + }, + }, + ], + RootDeviceName='/dev/sda1', + VirtualizationType='hvm', + Name=image_name, + Description='Image created from snapshot in shutdown state', + Architecture= 'x86_64' + +) + +# Print the newly created image ID +print(f"Image ID: {response['ImageId']}") diff --git a/terraform/environments/apex/zipfiles/dbconnect.zip b/terraform/environments/apex/zipfiles/dbconnect.zip new file mode 100644 index 00000000000..e53ec7c9c93 Binary files /dev/null and b/terraform/environments/apex/zipfiles/dbconnect.zip differ diff --git a/terraform/environments/apex/zipfiles/dbsnapshot.zip b/terraform/environments/apex/zipfiles/dbsnapshot.zip new file mode 100644 index 00000000000..bad655477ae Binary files /dev/null and b/terraform/environments/apex/zipfiles/dbsnapshot.zip differ diff --git a/terraform/environments/apex/zipfiles/nodejs.zip b/terraform/environments/apex/zipfiles/nodejs.zip new file mode 100644 index 00000000000..03842095203 Binary files /dev/null and b/terraform/environments/apex/zipfiles/nodejs.zip differ