Home > front end >  How to reference a zip file uploaded in an s3 bucket in your terraform lambda code?
How to reference a zip file uploaded in an s3 bucket in your terraform lambda code?

Time:08-15

I've working on a project in which the s3 bucket in aws is already created via console and the lambda code is already there as an object. I'm creating a terraform script in which I will reference that zip and then create a lambda function and publish it. Incase there's any change detected in the code (the code zip can be changed from console), then it should publish latest. How can I do that? Currently I'm getting errror-

module "student_lambda"{
source = "https://....." // I'm using a template which creates lambda function
handler..
s3_bucket = "SaintJoseph"
s3_key = "grade5/studentlist.zip"
source_code_hash = filebase64sha256("/grade5/studentlist.zip").etag
.....
}

My bucket structure

SaintJoseph -- bucketname

  • grade5
    • studentlist.zip
    • subjectlist.zip
  • grade6

Errors I'm getting in plan -

  1. Error in function call - Call to function filebase64sha256 failed: open grade5/studentlist.zip: no such file or directory

  2. The bucket key or source is invalid.

Can someone please also help to let me know what to use like etag/source_code_hash, etc so that it only takes changes when zip file is changed and how to remove existing error?

CodePudding user response:

filebase64sha256 works only on local filesystem. To reference etag of an s3 object you have to use aws_s3_object data source. The source returns etag.

  • Related