javascript - aws - CloudFront createInvalidation() 方法参数在使用 promises 时出错

标签 javascript amazon-web-services typescript aws-sdk amazon-cloudfront

适用于 JavaScript 的 AWS 开发工具包允许在调用 AWS 服务类的方法时使用 promise 而不是回调。以下是 S3 的示例。 (我正在使用 TypeScript 和无服务器框架进行开发)

const s3 = new S3({ apiVersion: '2006-03-01' });

async function putFiles () {
      await s3.putObject({
        Bucket: 'my-bucket',
        Key: `test.js`,
        Body: Buffer.from(file, 'binary') // assume that the file variable was defined above.
      }).promise();
}

上面的函数工作得很好,我们将桶参数作为唯一的参数传递给方法。

但是,当我尝试通过调用 AWS CloudFront 类上的 createInvalidation() 方法来执行类似操作时,它给我一个错误,指出参数不匹配。

以下是我的代码和我得到的错误。

const cloudfront = new aws.CloudFront();

async function invalidateFiles() {
      await this.cloudfront.createInvalidation({
        DistributionId: 'xxxxxxxxxxx',
        InvalidationBatch: {
          Paths: {
            Quantity: 1,
            Items: [`test.js`],
          },
        },
      }).promise();
}

Arguements Error

有人可以帮忙解决这个问题吗?

最佳答案

您没有将 CallerReference 作为参数传递。

const cloudfront = new aws.CloudFront();
async function invalidateFiles() {
    await cloudfront.createInvalidation({
        DistributionId: 'xxxxxxxxxxx',
        InvalidationBatch: {
            CallerReference: `SOME-UNIQUE-STRING-${new Date().getTime()}`,
            Paths: {
                Quantity: 1,
                Items: ['test.js'],
            },
        },
    }).promise();
}

关于javascript - aws - CloudFront createInvalidation() 方法参数在使用 promises 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50055281/

相关文章:

javascript - 如何使用Typescript定义强类型电子邮件模板参数?

amazon-s3 - S3 中文件名的最大长度是多少

amazon-web-services - 由于配置错误,执行失败:API Gateway 无权承担提供的角色 arn:aws:iam::XXXXXXXXXXXX:role/auth

angular - Angular 中的编译上下文是什么?

Angular Mat 选择 CompareWith ID 编号,并发出整个对象

asp.net - React useState 崩溃

javascript - 使用循环从数组中删除空值的最简单方法是什么(Js)

javascript - 如何转到 Angularjs 表达式中数组的下一项?

javascript - 加载资源失败,空白页

amazon-web-services - Amazon SQS(简单排队服务)速度?