6

[AWS s3 undefined 0.006s 0 retries] headObject({ Bucket: 'mypicturebank', Key: 'testing' }) There was an error creating your album: TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be one of type string, TypedArray, or DataView. Received type undefined

Ken G
  • 61
  • 2

2 Answers2

1

@Ken G I'm not sure what language or framework you are using, though I ran across the similar error message The "key" argument must be one of type string, TypedArray, or DataView. Received type undefined just now.

In my case and for anyone else who stumbles across this, it was because I was providing the PascalCase AWS credentials which are returned from AWS STS.assumeRole, where I needed to provide camelCase AWS credentials keys:

import AWS from 'aws-sdk'

# Bad
const s3 = new AWS.S3({
  credentials: {
    AccessKeyId: process.env.AWS_ACCESS_KEY,
    SecretAccessKey: process.env.AWS_SECRET_KEY,
  },
  ...
})

# Good
const s3 = new AWS.S3({
  credentials: {
    accessKeyId: process.env.AWS_ACCESS_KEY,
    secretAccessKey: process.env.AWS_SECRET_KEY,
  },
  ...
})

I am using the aws-sdk for JavaScript on macOS with Node v10.16.2, with the goal of using s3.createPresignedPost.

Possibly related, on an AWS Lambda instance running node 10.x I was seeing a different error message for the same code: Key must be a buffer.

pzrq
  • 1,626
  • 1
  • 18
  • 24
0

This issue could be also caused by the reason if you using some env variable in your code and it doesn't exist in the env file or is undefined in it like I was using file stack api so shared key required which is actually missing in the env file.

Himanshu Joshi
  • 100
  • 1
  • 5