node.js - Node.js 中的 AWS lambda 配置

标签 node.js express aws-lambda serverless

我使用下面的命令来配置 aws lambda

serverless config credentials --provider aws --key xxxx --secret xxxx

它说已在'.aws/credentials'中更新,但我找不到这样的文件或目录。

如何将其配置为从配置文件中读取,因为它对于 dev 、 qa 或 prod 来说是不同的

我运行以下命令来部署

sls deploy

谢谢

最佳答案

您计算机中 aws 凭证文件的位置

~/.aws

在 Windows 计算机中,凭证文件的文件路径为 C:\Users\.aws。确保 .aws 文件夹未隐藏

.aws 目录中凭证文件内的凭证信息

[default]
aws_access_key_id = xxxxxxxxx
aws_secret_access_key = yyyyy

[qa]
aws_access_key_id = xxxxxxxxx
aws_secret_access_key = yyyyy

[prod]
aws_access_key_id = xxxxxxxxx
aws_secret_access_key = yyyyy

您可以在以下文件中手动添加多个配置文件 [dev/test/preprod/qa]。

当您的计算机中安装了 aws cli 时,您还可以使用以下命令添加 aws 配置文件。

aws configure --profile prod

AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: ENTER

为了在 AWS 中部署无服务器,请使用以下命令

serverless deploy //Use default profile and proceed deployment
serverless deploy --aws-profile qa //Deploy in QA environment  
serverless deploy --aws-profile prod //Deploy in Production environment  

有关无服务器部署的更多详细信息,请参阅以下文档 Serverless Deployment

关于node.js - Node.js 中的 AWS lambda 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50797488/

相关文章:

amazon-web-services - 在 AWS API 上获取 ThrottlingException : Rate exceeded, 状态代码:400

amazon-dynamodb - 使用 DynamoDB 的无服务器框架 : Lambda function work, 但数据尚未保存到 DynamoDB

node.js - 使用 Docker 为 Node、我的基于 Express 的 Node 应用程序、MongoDb 和 NodeBB 构建图像,通过 Passport 连接

javascript - PassportJs Google Auth2 失败重定向不起作用

node.js - 启动时嗅探时 Elasticsearch 没有事件连接

Javascript数组解析

javascript - Express Gateway 启用日志

c# - 在 .net 核心项目中发布时获取 Assets 文件没有 targetframework 异常

javascript - 将新属性动态添加到 Node 中的现有 JSON 数组

javascript - 监听特定端口时接收广播包