DEV Community

Cover image for Terraform Test and AWS Lambda
6

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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

The state of AWS Serverless Development cover image

The state of AWS Serverless Development

Serverless development using AWS Lambda enables scalable applications, with best practices based on provider requirements. Optimized runtime, package deployment, and lifecycle knowledge can increase efficiency and savings.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay