1

在我当前的项目中,我们正在尝试迁移到 AWS SDK 版本 3(Javascript)。我们正在使用 s3 对象 lambda,并且遇到了WriteGetObjectResponseCommand命令问题。

WriteGetObjectResponseCommand代码:

import { S3Client, S3 } from '@aws-sdk/client-s3';
const s3Client = new S3Client({});

async function passTransformedPhoto(
  body: Buffer,
  outputRoute: string,
  outputToken: string,
): Promise<WriteGetObjectResponseCommandOutput> {
  try {
    const writeGetObjectParams: WriteGetObjectResponseCommandInput = {
      RequestRoute: outputRoute,
      RequestToken: outputToken,
      Body: body,
    };

    const command = new WriteGetObjectResponseCommand(writeGetObjectParams);

    return s3Client.send(command);
  } catch (e) {
    console.log('Error happens in passTransformedPhoto', e);
  }

聚合客户端的相同问题:

import { S3Client, S3 } from '@aws-sdk/client-s3';
const s3Aggregated = new S3({});

async function passTransformedPhoto(body: Buffer, outputRoute: string, outputToken: string) {
  try {
    const result = await s3Aggregated.writeGetObjectResponse({
      RequestRoute: outputRoute,
      RequestToken: outputToken,
      Body: body,
    });
    return result;
  } catch (e) {
    console.log('Error happens in passTransformedPhoto', e);
  }
}

错误:

INFO    TypeError: Cannot destructure property 'service' of 'bucketName' as it is undefined.
    at getEndpointFromArn (/var/task/node_modules/@aws-sdk/middleware-bucket-endpoint/dist/cjs/bucketHostname.js:26:13)
    at Object.bucketHostname (/var/task/node_modules/@aws-sdk/middleware-bucket-endpoint/dist/cjs/bucketHostname.js:17:13)
    at /var/task/node_modules/@aws-sdk/middleware-bucket-endpoint/dist/cjs/bucketEndpointMiddleware.js:47:67
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

环境:

@aws-sdk/client-s3: 3.18.0
Node.js: v 14.17.0
typescript: 4.3.2

非常感谢您对此问题的任何帮助或澄清。

4

1 回答 1

0

也许尝试包括所有预期的 S3Client 配置选项:

const config = {
    region: <region>,
    bucketEndpoint: true,
}

const client = new S3Client(config);
于 2022-02-05T14:15:03.323 回答