Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

We're getting an error when users are trying to sign up and create new accounts/ albums using AWS. See terminal message below

[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

like image 613
Ken G Avatar asked May 17 '18 22:05

Ken G


1 Answers

@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.

like image 98
pzrq Avatar answered Nov 15 '22 09:11

pzrq