Node.js AWS Cloudfront节点JS:请求路径包含未转义字符
我正在尝试在从CI管道进行新部署后使CloudFront缓存无效 使用的软件包: 我得到以下错误Node.js AWS Cloudfront节点JS:请求路径包含未转义字符,node.js,amazon-web-services,aws-sdk,amazon-cloudfront,Node.js,Amazon Web Services,Aws Sdk,Amazon Cloudfront,我正在尝试在从CI管道进行新部署后使CloudFront缓存无效 使用的软件包: 我得到以下错误 { err: TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters at new ClientRequest (_http_client.js:115:13) at Object.request (https.js:289:10) at CloudFront.request
{ err:
TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters
at new ClientRequest (_http_client.js:115:13)
at Object.request (https.js:289:10)
at CloudFront.request (/home/circleci/****-frontend-v2/node_modules/cloudfront/lib/index.js:158:19)
at CloudFront.createInvalidation (/home/circleci/****-frontend-v2/node_modules/cloudfront/lib/index.js:383:18)
at invalidate (/home/circleci/****-frontend-v2/publish.ts:214:10)
at Object.<anonymous> (/home/circleci/****-frontend-v2/publish.ts:18:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1043:23)
at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(anonymous function) [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1046:12) }
{err:
TypeError[ERR_UNESCAPED_CHARACTERS]:请求路径包含未转义字符
在新的客户端请求中(_http_client.js:115:13)
根据Object.request(https.js:289:10)
在CloudFront.request(/home/circleci/**-frontend-v2/node_modules/CloudFront/lib/index.js:158:19)
在CloudFront.createInvalidation(/home/circleci/**-frontend-v2/node_modules/CloudFront/lib/index.js:383:18)
失效时(/home/circleci/***-frontend-v2/publish.ts:214:10)
在对象上。(/home/circleci/**-frontend-v2/publish.ts:18:1)
at模块编译(内部/modules/cjs/loader.js:778:30)
在Module.m._compile(/usr/local/lib/node_modules/ts node/src/index.ts:1043:23)
at Module._extensions..js(internal/modules/cjs/loader.js:789:10)
at Object.require.extensions.(匿名函数)[as.ts](/usr/local/lib/node_modules/ts node/src/index.ts:1046:12)}
示例代码:我已经尝试了很多排列
function invalidate(appName: string) {
for (let index = 0; index < 4; index++) {
try {
const params = {
DistributionId: '***********',
InvalidationBatch: {
CallerReference: new Date().getTime().toString(),
Paths: {
Quantity: index,
Items: ['*'],
},
},
};
console.log(JSON.stringify(params, undefined, 2));
require('cloudfront')
.createClient(options.key, options.secret)
.createInvalidation(params, (err: any, data: any) => {
if (err) console.log({ err, stack: err.stack });
else console.log({ data });
});
} catch (err) {
console.log({ err });
}
try {
const params = {
DistributionId: '***********',
InvalidationBatch: {
CallerReference: new Date().getTime().toString(),
Paths: {
Quantity: index,
Items: [`${appName.trim()}/index.html`],
},
},
};
console.log(JSON.stringify(params, undefined, 2));
require('cloudfront')
.createClient(options.key, options.secret)
.createInvalidation(params, (err: any, data: any) => {
if (err) console.log({ err, stack: err.stack });
else console.log({ data });
});
} catch (err) {
console.log({ err });
}
try {
const params = {
DistributionId: '***********',
InvalidationBatch: {
CallerReference: new Date().getTime().toString(),
Paths: {
Quantity: index,
Items: [appName.trim(), `index.html`],
},
},
};
console.log(JSON.stringify(params, undefined, 2));
require('cloudfront')
.createClient(options.key, options.secret)
.createInvalidation(params, (err: any, data: any) => {
if (err) console.log({ err, stack: err.stack });
else console.log({ data });
});
} catch (err) {
console.log({ err });
}
try {
const params = {
DistributionId: '***********',
InvalidationBatch: {
CallerReference: new Date().getTime().toString(),
Paths: {
Quantity: index,
Items: [`/${appName.trim()}/index.html`],
},
},
};
console.log(JSON.stringify(params, undefined, 2));
require('cloudfront')
.createClient(options.key, options.secret)
.createInvalidation(params, (err: any, data: any) => {
if (err) console.log({ err, stack: err.stack });
else console.log({ data });
});
} catch (err) {
console.log({ err });
}
try {
const params = {
DistributionId: '***********',
InvalidationBatch: {
CallerReference: new Date().getTime().toString(),
Paths: {
Quantity: index,
Items: [`/my-aap/*`],
},
},
};
console.log(JSON.stringify(params, undefined, 2));
require('cloudfront')
.createClient(options.key, options.secret)
.createInvalidation(params, (err: any, data: any) => {
if (err) console.log({ err, stack: err.stack });
else console.log({ data });
});
} catch (err) {
console.log({ err });
}
}
}
函数失效(appName:string){
对于(让index=0;index<4;index++){
试一试{
常量参数={
DistributionId:“*************”,
失效批次:{
CallerReference:new Date().getTime().toString(),
路径:{
数量:指数,
项目:['*'],
},
},
};
log(JSON.stringify(params,未定义,2));
需要('cloudfront')
.createClient(options.key,options.secret)
.CreateInvalization(参数,(错误:任意,数据:任意)=>{
if(err)console.log({err,stack:err.stack});
else console.log({data});
});
}捕捉(错误){
log({err});
}
试一试{
常量参数={
DistributionId:“*************”,
失效批次:{
CallerReference:new Date().getTime().toString(),
路径:{
数量:指数,
条目:[`${appName.trim()}/index.html`],
},
},
};
log(JSON.stringify(params,未定义,2));
需要('cloudfront')
.createClient(options.key,options.secret)
.CreateInvalization(参数,(错误:任意,数据:任意)=>{
if(err)console.log({err,stack:err.stack});
else console.log({data});
});
}捕捉(错误){
log({err});
}
试一试{
常量参数={
DistributionId:“*************”,
失效批次:{
CallerReference:new Date().getTime().toString(),
路径:{
数量:指数,
Items:[appName.trim(),`index.html`],
},
},
};
log(JSON.stringify(params,未定义,2));
需要('cloudfront')
.createClient(options.key,options.secret)
.CreateInvalization(参数,(错误:任意,数据:任意)=>{
if(err)console.log({err,stack:err.stack});
else console.log({data});
});
}捕捉(错误){
log({err});
}
试一试{
常量参数={
DistributionId:“*************”,
失效批次:{
CallerReference:new Date().getTime().toString(),
路径:{
数量:指数,
条目:[`/${appName.trim()}/index.html`],
},
},
};
log(JSON.stringify(params,未定义,2));
需要('cloudfront')
.createClient(options.key,options.secret)
.CreateInvalization(参数,(错误:任意,数据:任意)=>{
if(err)console.log({err,stack:err.stack});
else console.log({data});
});
}捕捉(错误){
log({err});
}
试一试{
常量参数={
DistributionId:“*************”,
失效批次:{
CallerReference:new Date().getTime().toString(),
路径:{
数量:指数,
项目:[`/my aap/*`],
},
},
};
log(JSON.stringify(params,未定义,2));
需要('cloudfront')
.createClient(options.key,options.secret)
.CreateInvalization(参数,(错误:任意,数据:任意)=>{
if(err)console.log({err,stack:err.stack});
else console.log({data});
});
}捕捉(错误){
log({err});
}
}
}