AWS JavaScript SDK V3是否会自动从本地配置读取凭据?
我正在查看此页面 https://docs.aws.amazon.com/sdk-for-javascript ... ,这似乎暗示SDK将查看〜/.aws/.aws/recertentials
和如果没有AWS_PROFILE环境VAR,请使用[默认]
配置文件。
我正在我的本地计算机上运行一个nextJS应用程序,试图列出S3存储桶,获取错误:凭证缺少
。
我真的很想不必在Env Vars中指定信用,因为稍后我将将该应用程序部署到ECS,在那里它将使用IAM角色进行访问。
这是我的代码:
import { ListBucketsCommand } from '@aws-sdk/client-s3';
import React, { useEffect } from 'react';
import { s3Client } from '../lib/s3Client';
const S3Buckets = () => {
useEffect(() => {
async function getS3Buckets() {
const input = {};
const command = new ListBucketsCommand(input);
const res = await s3Client.send(command);
console.log(res);
}
getS3Buckets();
}, []);
return <div>{/* S3 Buckets eventually listed here */}</div>;
};
export default S3Buckets;
带有S3Client助手如下:
import { S3Client } from '@aws-sdk/client-s3';
export const s3Client = new S3Client({ region: process.env.AWS_REGION });
I'm looking at this page https://docs.aws.amazon.com/sdk-for-javascript... and it seems to imply that the SDK will look at ~/.aws/credentials
and take the [default]
profile if there is no AWS_PROFILE environment var.
I'm running a NextJS app on my local machine trying to list S3 buckets, getting Error: Credential is missing
.
I would really love not to have to specify the creds in env vars as I'll be deploying the app to ECS later where it will use an IAM Role for access.
Here's my code:
import { ListBucketsCommand } from '@aws-sdk/client-s3';
import React, { useEffect } from 'react';
import { s3Client } from '../lib/s3Client';
const S3Buckets = () => {
useEffect(() => {
async function getS3Buckets() {
const input = {};
const command = new ListBucketsCommand(input);
const res = await s3Client.send(command);
console.log(res);
}
getS3Buckets();
}, []);
return <div>{/* S3 Buckets eventually listed here */}</div>;
};
export default S3Buckets;
with the s3Client helper as below:
import { S3Client } from '@aws-sdk/client-s3';
export const s3Client = new S3Client({ region: process.env.AWS_REGION });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论