Skip to content

Commit

Permalink
BRS-897: Stubbing out delete endpoints for activity and subArea (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltruong authored Apr 28, 2023
1 parent 1eb82e0 commit d5a0bb2
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lambda/activity/DELETE/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.handler = async (event, context) => {
logger.debug("Activity delete:", event);
return sendResponse(501, { msg: "Error: Not implemented." }, context);
};

5 changes: 5 additions & 0 deletions lambda/subArea/DELETE/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.handler = async (event, context) => {
logger.debug("SubArea delete:", event);
return sendResponse(501, { msg: "Error: Not implemented." }, context);
};

16 changes: 16 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ functions:
path: /subArea
cors: true

subAreaDelete:
handler: lambda/subArea/DELETE/index.handler
events:
- http:
method: DELETE
path: /subArea
cors: true

###########
# Activity
###########
Expand Down Expand Up @@ -111,6 +119,14 @@ functions:
path: /activity
cors: true

activityDelete:
handler: lambda/activity/DELETE/index.handler
events:
- http:
method: DELETE
path: /activity
cors: true

activityRecordLock:
handler: lambda/activity/POST/index.handleLock
events:
Expand Down
59 changes: 59 additions & 0 deletions terraform/src/activity.tf
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,46 @@ resource "aws_lambda_permission" "activityPutPermission" {
source_arn = "${aws_api_gateway_rest_api.apiLambda.execution_arn}/*/PUT/activity"
}

#deleteActivity
resource "aws_lambda_function" "activityDeleteLambda" {
function_name = "activity-delete-${random_string.postfix.result}"

filename = "artifacts/activityDelete.zip"
source_code_hash = filebase64sha256("artifacts/activityDelete.zip")

handler = "lambda/activity/DELETE/index.handleDelete"
runtime = "nodejs14.x"
timeout = 30
publish = "true"

memory_size = 128

role = aws_iam_role.databaseReadRole.arn

environment {
variables = {
SSO_ISSUER = data.aws_ssm_parameter.sso_issuer.value,
SSO_JWKSURI = data.aws_ssm_parameter.sso_jwksuri.value,
TABLE_NAME = aws_dynamodb_table.ar_table.name,
LOG_LEVEL = "info"
}
}
}

resource "aws_lambda_alias" "activityDeleteLambdaLatest" {
name = "latest"
function_name = aws_lambda_function.activityDeleteLambda.function_name
function_version = aws_lambda_function.activityDeleteLambda.version
}

resource "aws_lambda_permission" "activityDeletePermission" {
statement_id = "activityDeletePermissionInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.activityDeleteLambda.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.apiLambda.execution_arn}/*/DELETE/activity"
}

#lockActivityRecord
resource "aws_lambda_function" "activityRecordLockLambda" {
function_name = "activity-record-lock-${random_string.postfix.result}"
Expand Down Expand Up @@ -263,6 +303,25 @@ resource "aws_api_gateway_integration" "activityPutIntegration" {
uri = aws_lambda_function.activityPutLambda.invoke_arn
}

// Defines the HTTP DELETE /activity API
resource "aws_api_gateway_method" "activityDelete" {
rest_api_id = aws_api_gateway_rest_api.apiLambda.id
resource_id = module.activityResource.resource.id
http_method = "DELETE"
authorization = "NONE"
}

// Integrates the APIG to Lambda via POST method
resource "aws_api_gateway_integration" "activityDeleteIntegration" {
rest_api_id = aws_api_gateway_rest_api.apiLambda.id
resource_id = module.activityResource.resource.id
http_method = aws_api_gateway_method.activityDelete.http_method

integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.activityDeleteLambda.invoke_arn
}

# Resources - lock activitys
module "activityRecordLockResource" {
source = "./modules/cors-enabled-api-resource"
Expand Down
2 changes: 2 additions & 0 deletions terraform/src/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ resource "aws_api_gateway_deployment" "apideploy" {
aws_api_gateway_integration.subAreaGetIntegration,
aws_api_gateway_integration.subAreaPostIntegration,
aws_api_gateway_integration.subAreaPutIntegration,
aws_api_gateway_integration.subAreaDeleteIntegration,
aws_api_gateway_integration.activityGetIntegration,
aws_api_gateway_integration.activityPostIntegration,
aws_api_gateway_integration.activityPutIntegration,
aws_api_gateway_integration.activityDeleteIntegration,
aws_api_gateway_integration.activityRecordLockIntegration,
aws_api_gateway_integration.activityRecordUnlockIntegration,
aws_api_gateway_integration.exportGetIntegration,
Expand Down
60 changes: 60 additions & 0 deletions terraform/src/subArea.tf
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,47 @@ resource "aws_lambda_permission" "subAreaPutPermission" {
source_arn = "${aws_api_gateway_rest_api.apiLambda.execution_arn}/*/PUT/subArea"
}

#deleteSubArea
resource "aws_lambda_function" "subAreaDeleteLambda" {
function_name = "subArea-delete-${random_string.postfix.result}"

filename = "artifacts/subAreaDelete.zip"
source_code_hash = filebase64sha256("artifacts/subAreaDelete.zip")

handler = "lambda/subArea/DELETE/index.handler"
runtime = "nodejs14.x"
timeout = 30
publish = "true"

memory_size = 128

role = aws_iam_role.databaseReadRole.arn

environment {
variables = {
SSO_ISSUER = data.aws_ssm_parameter.sso_issuer.value,
SSO_ORIGIN = data.aws_ssm_parameter.sso_origin.value,
SSO_JWKSURI = data.aws_ssm_parameter.sso_jwksuri.value,
TABLE_NAME = aws_dynamodb_table.ar_table.name,
LOG_LEVEL = "info"
}
}
}

resource "aws_lambda_alias" "subAreaDeleteLambdaLatest" {
name = "latest"
function_name = aws_lambda_function.subAreaDeleteLambda.function_name
function_version = aws_lambda_function.subAreaDeleteLambda.version
}

resource "aws_lambda_permission" "subAreaDeletePermission" {
statement_id = "subAreaDeletePermissionInvoke"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.subAreaDeleteLambda.function_name
principal = "apigateway.amazonaws.com"
source_arn = "${aws_api_gateway_rest_api.apiLambda.execution_arn}/*/DELETE/subArea"
}

# Resources - subAreas
module "subAreaResource" {
source = "./modules/cors-enabled-api-resource"
Expand Down Expand Up @@ -185,3 +226,22 @@ resource "aws_api_gateway_integration" "subAreaPutIntegration" {
type = "AWS_PROXY"
uri = aws_lambda_function.subAreaPutLambda.invoke_arn
}

// Defines the HTTP DELETE /subArea API
resource "aws_api_gateway_method" "subAreaDelete" {
rest_api_id = aws_api_gateway_rest_api.apiLambda.id
resource_id = module.subAreaResource.resource.id
http_method = "DELETE"
authorization = "NONE"
}

// Integrates the APIG to Lambda via POST method
resource "aws_api_gateway_integration" "subAreaDeleteIntegration" {
rest_api_id = aws_api_gateway_rest_api.apiLambda.id
resource_id = module.subAreaResource.resource.id
http_method = aws_api_gateway_method.subAreaDelete.http_method

integration_http_method = "POST"
type = "AWS_PROXY"
uri = aws_lambda_function.subAreaDeleteLambda.invoke_arn
}

0 comments on commit d5a0bb2

Please sign in to comment.