如何在 Google Firebase 云功能中设置 AWS S3 凭证? [英] How to set AWS S3 credentials in a Google Firebase cloud function?

查看:13
本文介绍了如何在 Google Firebase 云功能中设置 AWS S3 凭证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的 Firebase 云功能能够访问 AWS S3.为此,在我的 index.js 文件中,我试图告诉 AWS 查看 awscred.json 文件以获取如下连接凭据:

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:

错误:ENOENT:没有这样的文件或目录,打开 './awscred.json'

Error: ENOENT: no such file or directory, open './awscred.json'

如何将文件awscred.json"添加到云功能包中?我需要在 package.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?

推荐答案

只需将 awscred.json 文件与源代码一起放在您的函数源代码部署文件夹中即可.它将与所有其他源代码一起部署,以便在 Cloud Functions 中运行时可以使用它.如果你想从相对路径./awecred.json"加载它,那么它应该存在于源文件旁边.

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.

这篇关于如何在 Google Firebase 云功能中设置 AWS S3 凭证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆