我的问题是NodeJS中aws createPresignedPost方法的凭据错误。下面是我的代码块:
export async function getCognitoCredentials() {
const stsClient = new STSClient({ region: 'eu-west-1' })
const assumeRoleCommand = new AssumeRoleCommand({
RoleArn: `arn:aws:iam::${id}:role/new-iam-cross-account-role`,
RoleSessionName: 'serviceName',
DurationSeconds: 3600,
})
const assumeRoleResponse = await stsClient.send(assumeRoleCommand)
return {
accessKeyId: assumeRoleResponse.Credentials?.AccessKeyId!,
secretAccessKey: assumeRoleResponse.Credentials?.SecretAccessKey!,
sessionToken: assumeRoleResponse.Credentials?.SessionToken!,
}
}
const s3Client = new S3Client({ region: 'eu-west-1', credentials: getCognitoCredentials })
console.log(s3Client)
const { url, fields } = await createPresignedPost(s3Client, {
Bucket: 'bucketName',
Key: path,
Conditions: [
['content-length-range', min, max],
['starts-with', '$Content-Type', 'image/'],
],
Expires: 600,
})
console.log('url >>>', url)
console.log('fields >>>', fields)
我得到以下错误:
Uncaught (in promise) Error: Credential is missing
我查了证件,应该是真的。我不明白为什么我得到的错误。任何帮助将不胜感激。谢谢
1条答案
按热度按时间ki0zmccv1#
getCognitoCredentials
是一个函数,但你没有调用它:尝试调用该函数,看看是否得到相同的错误。