How can I use the terraform for deployment of AWS Lambda functions?

69    Asked by Deepalisingh in AWS , Asked on Mar 6, 2024

I am currently engaged as a cloud infrastructure engineer and I am currently tasked with automation of the development of AWS Lambda functions by using the technology of terraform within my organization's AWS environment. Explain to me how can I utilize Terraform for the deployment of AWS Lambda functions and managing associated Resources such as permission, triggers, and even environment variables. 

In the context of AWS, you can deploy the AWS Lambda functions by using the technique of terraform using its Configuration language. Here is a basic example given of how you can deploy a lambda function by using terraform:-


Provider “aws” {
  Region = “us-west-2” # Update with your desired AWS region
}
Resource “aws_lambda_function” “example_lambda” {
  Function_name = “example_lambda_function”
  Handler = “index.handler”
  Runtime = “nodejs14.x”
  Filename = “lambda_function.zip”
  Source_code_hash = filebase64sha256(“lambda_function.zip”)
  Role = aws_iam_role.lambda_exec_role.arn
}
Resource “aws_iam_role” “lambda_exec_role” {
  Name = “lambda-exec-role”
  Assume_role_policy = jsonencode({
    “Version” : “2012-10-17”,
    “Statement” : [
      {
        “Effect” : “Allow”,
        “Principal” : {
          “Service” : “lambda.amazonaws.com”
        },
        “Action” : “sts:AssumeRole”
      }
    ]
  })
}

Your Answer

Interviews

Parent Categories