S3에 파일 올리는 코드가 세팅되어 있어 실행하니
CredentialsProviderError: Could not load credentials from any providers
위와 같은 에러가 발생했다
확인되어서 찾아보다가 해결해서 방법 정리해놓기
aws sdk를 이용해서 접근할 때 ~/.aws/~
에 정의되어 있는 정보를 접근한다고 한다.
확인되는 값이 없다면 값을 세팅해놓아야 한다.
cat ~/.aws/config
cat ~/.aws/credentials
입력했을 때 값이 잘 출력된다면 세팅이 되어있다는 것
만약 cat: /Users/~/.aws/credentials : No such file or directory
과 같이 라고 출력 된다면
파일이 없다는 것을 의미하니 파일을 생성하고 aws 정보를 추가 해놓아야 한다.
aws --version // 안뜨면 설치해야 됨
aws cli 설치 : https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/getting-started-install.html
MAC OS
위 명령어 그대로 따라친다curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg" sudo installer -pkg AWSCLIV2.pkg -target / curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg" sudo installer -pkg ./AWSCLIV2.pkg -target / which aws aws --version
mkdir /.aws // 디렉토리 만들기
touch ~/.aws/credentials // 필요에 따라 파일만들기
touch ~/.aws/conifg // 필요에 따라 파일만들기
vi ~/.aws/credentials // 파일 열기
파일 연 다음에 i
로 편집모드로 변경한 뒤 esc
눌러서 편집모드 종료하고 :wq
나오기 !
[default]
aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
region = 사용 리전
이제 cat
명령어로 확인하면 세팅 된 값이 잘 나온다!
S3 업로드도 잘된다 😌
근데 블로그 작성하면서 다시 확인해보니까 변수 선언만 해놓고
아래처럼 값 전달 안하고 region만 주고 있었다 ^^... 😮💨
const s3Client = new S3Client({
region: aws.region,
credentials: {
accessKeyId: '',
secretAccessKey: '',
},
});
이미 세팅이 되어있어서 아래와 같이 선언해주면 되는지는 잘 모르겠지만 aws type 따라 들어가면
import { Identity, IdentityProvider } from "./Identity";
export interface AwsCredentialIdentity extends Identity {
/**
* AWS access key ID
*/
readonly accessKeyId: string;
/**
* AWS secret access key
*/
readonly secretAccessKey: string;
/**
* A security or session token to use with these credentials. Usually
* present for temporary credentials.
*/
readonly sessionToken?: string;
}
export declare type AwsCredentialIdentityProvider = IdentityProvider<AwsCredentialIdentity>;
타입정의가 이렇게 되어있는걸 보니 위에 값으로 전달해주었어도 업로드가 잘 되었을거라 생각된다 ^_^..ㅎ