raosa
raosa

Reputation: 129

Storing a yaml file in aws lambda function

I am trying to load a yaml file from the folder template which has a file called Template-PROD.yaml Where and how can I store this yaml file so that it can be loaded in the lambda handler?

exports.handler = async (event) => {
     const templateFile = `/templates/Template-PROD`;
     const YamlBody =  yaml.load(fs.readFileSync(templateFile, 'utf8'), { schema: SCHEMA });

}


There is only one yaml file that needs to be stored so that the lambda can load it. If it can be stored in tmp folder, how can I do that?

Are there any helpful links/references on how it can be stored in tmp folder?

Thanks in advance

Upvotes: 1

Views: 985

Answers (1)

Ben Whaley
Ben Whaley

Reputation: 34406

There are a few ways to do it, but the easiest is probably to package your function code and the yaml file as a zip archive.

First, create a directory with your function in a python file and your template in the subdirectory so it looks something like this:

function-dir
├── function.py
└── templates
    └── file.yaml

Now you can create a zip archive of the code:

cd function-dir
zip -r ./deployment-package.zip .

Now, within the Lambda console, upload the zip file archive. When the Lambda Function executes, it will download and extract the archive, including the template.

See also this document for reference.

Upvotes: 1

Related Questions