gay*_*nbc 3 javascript amazon-web-services amazon-cloudfront typescript aws-sdk
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();
}
Run Code Online (Sandbox Code Playgroud)
上面的函数工作得很好,我们将存储桶参数作为唯一的参数传递给该方法。
但是,当我尝试通过调用 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();
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙解决这个问题吗?
您缺少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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2595 次 |
| 最近记录: |