我正在尝试使用适用于NodeJS的AWS开发工具包将字符串作为文件保存到AWS S3存储桶。PUT请求成功,但未在S3存储桶中创建文件。以下是我的代码段。
const s3 = new S3({ apiVersion: '2006-03-01' });
const JS_code = `
let x = 'Hello World';
`;
// I'm using the following method inside an async function.
await s3.putObject({
Bucket: 'my-bucket-gayashan',
Key: 'myFile.js',
ContentType:'binary',
Body: Buffer.from(JS_code, 'binary')
});
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?
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)
有人可以帮忙解决这个问题吗?
javascript amazon-web-services amazon-cloudfront typescript aws-sdk
我要在运行带有--prod选项而没有--prod选项的ng build命令时更改脚本标记的URL 。以下是一个示例。
ng build --prod
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<script src="https://my-site.net/prod.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
ng构建
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<script src="https://my-site.net/dev.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我该如何实现?