带有JS SDK的AWS Glacier-InvalidParameterValueException:无效的内容长度:0

时间:2019-04-15 21:21:56

标签: javascript node.js aws-sdk-js

我正在尝试使用JavaScript SDK将数据提交给Glacier。我正在密切关注NPM package中的代码示例,但收到400响应代码和一个错误。

我发送的文本文件不为空。

根据this,主体也应为字符串或斑点-我已经尝试过这些,但得到的结果相同。

我正在为accountId使用连字符,因为应该再次通过this来使用访问密钥来标识帐户。

我不是在后端配置AWS的人,但是我确信这些信条都是正确的:实际上,如果我更改了密钥,则会得到403响应,因此我可以肯定地确定此错误是“下游” ”。

执行以下完整脚本:

require('dotenv').load()

const { GlacierClient } = require('@aws-sdk/client-glacier-node/GlacierClient')
const { UploadArchiveCommand } = require('@aws-sdk/client-glacier-node/commands/UploadArchiveCommand')
const awsConfig = require('aws-config')
const fs = require('fs')
const path = require('path')

const glacier = new GlacierClient(awsConfig({
  region: 'us-east-1',
  sslEnabled: true,
  maxRetries: 3,
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  timeout: 15000
}))

const params = {
  accountId: '-',
  vaultName: process.env.AWS_GLACIER_VAULT_NAME,
  body: fs.createReadStream(path.join(__dirname, 'myfile.txt'))
}
const uploadArchiveCommand = new UploadArchiveCommand(params)
glacier.send(uploadArchiveCommand).then(console.log).catch(console.error)

出现此错误:

{ InvalidParameterValueException: Invalid Content-Length: 0
    at RestParser.exports.jsonErrorUnmarshaller [as parseServiceException] (/home/casey/Documents/code/manuscripts-app/shackles.io/node_modules/@aws-sdk/json-error-unmarshaller/build/index.js:36:70)
    at /home/casey/Documents/code/manuscripts-app/shackles.io/node_modules/@aws-sdk/protocol-rest/build/RestParser.js:27:29
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
  name: 'InvalidParameterValueException',
  message: 'Invalid Content-Length: 0',
  details: 
   { type: 'Client',
     code: 'InvalidParameterValueException',
     message: 'Invalid Content-Length: 0' },
  '$metadata': 
   { httpHeaders: 
      { 'x-amzn-requestid': 'HpR7HsuG7sSTOw0zckkqlHhVZvz2o8t7btwVBrNfxCuI2Lw',
        'content-type': 'application/json',
        'content-length': '95',
        date: 'Mon, 15 Apr 2019 21:14:27 GMT',
        connection: 'close' },
     httpStatusCode: 400,
     requestId: 'HpR7HsuG7sSTOw0zckkqlHhVZvz2o8t7btwVBrNfxCuI2Lw',
     extendedRequestId: undefined,
     cfId: undefined,
     retries: 0,
     totalRetryDelay: 0 } }

我在AWS方面的经验非常有限:非常感谢您的帮助。

0 个答案:

没有答案