[go: up one dir, main page]

DEV Community

Cover image for Terraform Test and AWS Lambda

Terraform Test and AWS Lambda

You may find my base repository here.

GitHub logo bervProject / lambda-sharp

Lambda use C# (.NET) Docker Image

Lambda Sharp Demo

Demo for Lambda Containerized .NET

LICENSE

MIT




Please see my previous post for the step-by-step creation of the lambda itself.

Designing the testing

I may extract some "constant" to variables, such as image_uri, lambda timeout, function_name, etc. After some extraction, we will write "basic" (unit) testing without end-to-end testing.

variables {
  lambda_image = "test"
}

run "valid_image" {

  command = plan

  assert {
    condition     = aws_lambda_function.lambda_container_demo.image_uri == "test"
    error_message = "AWS Lambda Function Image URI did not match"
  }

}

run "valid_function_name" {

  command = plan

  assert {
    condition     = aws_lambda_function.lambda_container_demo.function_name == "lambda_container_demo"
    error_message = "AWS Lambda Function Name did not match"
  }

}

run "valid_lambda_timeout" {

  command = plan

  assert {
    condition     = aws_lambda_function.lambda_container_demo.timeout == 60
    error_message = "AWS Lambda timeout did not match"
  }

}

run "valid_dynamo_db_capacity" {

  command = plan

  assert {
    condition     = aws_dynamodb_table.lambda_container_demo_dev.read_capacity == 20
    error_message = "Dynamo DB read capacity did not match"
  }

  assert {
    condition     = aws_dynamodb_table.lambda_container_demo_dev.write_capacity == 20
    error_message = "Dynamo DB write capacity did not match"
  }

}
Enter fullscreen mode Exit fullscreen mode

However, it's not challenging, right? I'll share more challenging tests (maybe end-to-end ones) after this post. Stay tuned!

Stay Tuned GIF

You may check this pull request for the changes.

Top comments (0)