title: Getting Error : error creating Lambda Function (1): ValidationException status code: 400
body: <p>I am attempting a project in Udacity's AWS Cloud Architect Nanodegree program. And am writing the code to deploy an AWS Lambda Function using Terraform. I believe I am supposed to use <code>greet_lambda.py</code> as the lambda function to be deployed through terraform. File is mentioned below and so far have executed the below steps:</p>
  <p>greet_lambda.py</p>
  <pre><code>import os
  def lambda_handler(event, context):
      return &quot;{} from Lambda!&quot;.format(os.environ['greeting'])
  </code></pre>
  <p>Zipped the lambda file:</p>
  <pre><code>$zip ../greet_lambda.zip greet_lambda.py
  </code></pre>
  <p>Created a bucket in S3:</p>
  <pre><code>$aws s3api create-bucket --bucket=dirai-terraform-lambda --region=us-east-1
  </code></pre>
  <p>Uploaded the zip file into S3:</p>
  <pre><code>$aws s3 cp greet_lambda.zip s3://dirai-terraform-lambda/v1.0.0/greet_lambda.zip
  </code></pre>
  <p>main.tf file:</p>
  <pre><code>terraform {
    required_providers {
      aws = {
        source = &quot;hashicorp/aws&quot;
      }
    }
  }
  
  provider &quot;aws&quot; {
     region = &quot;us-east-1&quot;
  }
  
  
  resource &quot;aws_iam_role&quot; &quot;lambda_role&quot; {
      name = &quot;lambda_role&quot;
      assume_role_policy = &lt;&lt;EOF
  {
    &quot;Version&quot;: &quot;2012-10-17&quot;,
    &quot;Statement&quot;: [
      {
        &quot;Action&quot;: &quot;sts:AssumeRole&quot;,
        &quot;Principal&quot;: {
          &quot;Service&quot;: &quot;lambda.amazonaws.com&quot;
        },
        &quot;Effect&quot;: &quot;Allow&quot;,
        &quot;Sid&quot;: &quot;&quot;
      }
    ]
  }
  EOF
  }
  
  resource &quot;aws_lambda_function&quot; &quot;test_lambda&quot; {
     function_name = &quot;greet_lambda&quot;
     s3_bucket = &quot;dirai-terraform-lambda&quot;
     s3_key    = &quot;v1.0.0/greet_lambda.zip&quot;
     handler = &quot;greet_lambda.lambda_handler&quot;
     runtime = &quot;python3.7&quot;
     role = &quot;aws_iam_role.lambda_role.arn&quot; 
  }
  </code></pre>
  <p>And I get the below error on $terraform apply:</p>
  <pre><code>Error: error creating Lambda Function (1): ValidationException: 
      status code: 400, request id: e6289eb7-40f5-4cf2-ba0a-e8b5ae656466
  
    on main.tf line 33, in resource &quot;aws_lambda_function&quot; &quot;test_lambda&quot;:
    33: resource &quot;aws_lambda_function&quot; &quot;test_lambda&quot; {
  </code></pre>
  <p>Please help me here what I could be doing wrong. The lambda is successfully exported into S3. But the terraform apply is failing.</p>