I want my Firebase cloud function to access AWS S3. To do that, in my index.js file I am trying to tell AWS to look at the awscred.json file to get the connection credentials like this:
// Load the SDK for JavaScript
var AWS = require('aws-sdk');
// Set the Region
AWS.config.loadFromPath('./awscred.json');
This works fine when I test it locally, but when I try to deploy to the cloud I get this error:
Error: ENOENT: no such file or directory, open './awscred.json'
How can I add the file 'awscred.json' to the cloud function package? Do I need to add something to the package.json file?
Just put the awscred.json file in your function source code deployment folder along with the source code. It will be deployed along with all the other source code so that it can be used while being run in Cloud Functions. If you want to load it from the relative path "./awecred.json" then it should exist right next to the source file.
So it turned out that during the deployment process (ie. from local machine to Google's servers) the index.js file is run on my local machine. The error was generated because there was no 'awscred.json' file in the directory I was running my 'firebase deploy' command, so the solution was to just execute that command in my functions directory instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With