1
votes

I have written terraform code which:

  1. Creates IAM Role
  2. Creates lambda functions and attaches the above created role
  3. Dynamo DB table creation
  4. Creates API gateway, resources and adds POST method with lambda integration.

The first 3 steps works well. However while creating and configuring the API gateway, I am encountering below error in resource aws_api_gateway_integration & aws_lambda_permission, where I am trying to attach the lambda function "save_course" to the POST method under "courses" resource

│ 
│   on main.tf line 117, in resource "aws_api_gateway_integration" "apigateway84f0f20":
│  117:   uri = module.awsLambda["save_course.py"].lambda_invoke_urn
│     ├────────────────
│     │ module.awsLambda["save_course.py"].lambda_invoke_urn is tuple with 1 element
│ 
│ Inappropriate value for attribute "uri": string required.
╵
╷
│ Error: Incorrect attribute value type
│ 
│   on main.tf line 141, in resource "aws_lambda_permission" "lambda_permission":
│  141:   function_name = module.awsLambda["save_course.py"].function_name
│     ├────────────────
│     │ module.awsLambda["save_course.py"].function_name is tuple with 1 element
│ 
│ Inappropriate value for attribute "function_name": string required.

Not sure how to access the tuple and extract the invoke_arn and function_name. After going through the generated terraform.tfstate file, I have tried different combinations to extract the required value. Not sure where I am wrong.

The terraform code along with generated terraform.tfstate file is available at my location: https://github.com/myanees284/lambda_website

git clone https://github.com/myanees284/lambda_website.git
terraform init
terraform apply -auto-approve

1

1 Answers

1
votes

Change your locals from

  lambda_invoke_urn=aws_lambda_function.lambda.*.invoke_arn
  lambda_name=aws_lambda_function.lambda.*.function_name

to

  lambda_invoke_urn=aws_lambda_function.lambda.invoke_arn
  lambda_name=aws_lambda_function.lambda.function_name