I am trying to add python klayer to lambda in terraform (as in snapshot done on console) but its giving error on terraform plan (Error: Import block target does not exist) (The target for the given import block does not exist)
I am not sure what is the correct terraform code for it, I tried to import and terraform plan failed.
Here is my code:
import {
to = aws_lambda_function.lambda_function
#to = aws_lambda_layer_version.test_layer
id = "arn:aws:lambda:eu-west-1:770693421928:layer:Klayers-p311-requests:3"
}
2
Answers
Thank you for your guidance, I am sure, as you said, if we list the ARN it should work. I will try it out and share result.
The method however, I used is different as under. Created a klayer, zipped, placed in S3 and referenced it and it worked.
(Edited after seeing MarkB’s comment on the question)
You are trying to import someone else’s layer into your Terraform state, which you can’t do because it’s not in your account.
To make use of that layer, you don’t need to import it at all, you can just list its ARN directly in the Lambda Function definition: