代码之家  ›  专栏  ›  技术社区  ›  gayashanbc

aws-CloudFront CreateInvalization()方法参数在使用承诺时出错

  •  3
  • gayashanbc  · 技术社区  · 6 年前

    AWS SDK for JavaScript允许在调用AWS服务类的方法时使用承诺而不是回调。下面是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();
    }
    

    上面的函数工作得非常好,我们将bucket参数作为唯一的参数传递给该方法。

    但是,当我试图通过在AWS CloudFront类上调用createInvalization()方法来执行类似的操作时,会出现一个错误,即参数不匹配。

    下面是我的代码和错误。

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

    Arguements Error

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

    1 回复  |  直到 6 年前
        1
  •  4
  •   MaiKaY    6 年前

    你错过了传球机会 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();
    }