javascript - aws - CloudFront createInvalidation() method arguments error when using promises
问题描述
AWS SDK for JavaScript allows to use promises instead of callbacks, when calling the methods of AWS Service classes. Following is an example for S3. (I'm using TypeScript along with the Serverless framework for development)
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();
}
The above function works perfectly fine, where we are passing the bucket parameters as the only argument to the method.
But, when I'm trying to do a similar operation by calling the createInvalidation() method on the AWS CloudFront class, it gives me an error saying that the arguments do not match.
Following is my code and the error I get.
const cloudfront = new aws.CloudFront();
async function invalidateFiles() {
await this.cloudfront.createInvalidation({
DistributionId: 'xxxxxxxxxxx',
InvalidationBatch: {
Paths: {
Quantity: 1,
Items: [`test.js`],
},
},
}).promise();
}
Can someone help with this issue please?
解决方案
您缺少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();
}
推荐阅读
- angular - 在角度 5 中访问服务器上的文件夹内的另一个应用程序的组件时出现 404 错误?
- arrays - 在 Swift 中创建具有自变量的项目“网格”?
- swift - first-where 的时间复杂度是多少?
- c++ - 设计许多单例的代码结构的更好方法
- javascript - 如何动画填充div上的背景颜色
- git - 如何允许使用 https 从我的 git 服务器进行克隆?
- reactjs - this.props 是否仅在将要呈现的组件中定义?
- amp-html - IFrame contents do not show up in an hidden div container
- mysql - 如何在 Mysql 中优化我的代码?
- mysql - 使用原始 sql 时的 Laravel SQL 参数绑定