0

I want to be able deploy some script files to aws lambda using a terraform file.

Here is a my file:

terraform {
  required_version = "0.11.7"
}

variable "region" {}


provider "aws" {
  region = "${var.region}"
  version = "2.00"
}



// Zip the scripts folder (thus creating a package) before supplying it to the lambda function.
data "archive_file" "package_zip" {
  type = "zip"
  source_dir = "${path.root}/scripts/"  # Path from top level module.
  output_path = "./sources.zip"
}

resource "aws_lambda_function" "anthony_test_lambda" {
  filename      = "lambda_function_payload.zip"
  function_name = "anthony_test_lambda"
  role          = "new-role"
  handler       = "lambda_function.lambda_handler"

  source_code_hash = "${data.archive_file.package_zip.output_base64sha256}"

  runtime = "python3.7"


}

I want to keep the script as flexible as possible because I may not the only one who will work on the script in the future.

I want to be able to drive the process by using AWS profile. Here is what I tried:

 export AWS_PROFILE=a_team
 tf apply

I got this error:

* provider.aws: No valid credential sources found for AWS Provider.
    Please see https://terraform.io/docs/providers/aws/index.html for more information on
    providing credentials for the AWS Provider

I cannot use AWS access key id and secret.

How can I fix this issue?

1 Answer 1

1

There might be a possible problem with the AWS_PROFILE environment variable, make sure AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID are unset. This will ensure that the keys which it is taking via the environment variable is from AWS_PROFILE environment variable.

Refer the Environment Variable section under https://www.terraform.io/docs/providers/aws/index.html article for how to set the environment variables for your secret and access keys.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .