我有一个AWS lambda,必须......
我可以处理最后一点,但我不知道如何阅读和解析该yaml文件。
以下是我需要完成的代码:
const AWS = require('aws-sdk');
const YAML = require('js-yaml');
const S3 = new AWS.S3();
module.exports.handler = (event, context, callback) => {
const [record] = event.Records;
const bucket = record.s3.bucket.name;
const { key } = record.s3.object;
const params = { Bucket: bucket, Key: key };
console.log(params);
S3.getObject(params).promise()
.then((x) => {
// ?????????????????????????????????????????
// HOW TO DO SOME MAGIC AND GET THE OBJECT ?
})
.then((fileContentObject) => {
// DO SOME WONDERFUL STAFF (example: console.log :) )
console.log(JSON.stringify(fileContentObject))
})
.then(() => callback)
.catch(callback);
};
随意建议另一种方法来读取和解析yaml文件。如果可能的话,我更喜欢Promise方法。
答案 0 :(得分:0)
我终于解决了这个问题。 "当然很简单!
以下是lambda中的代码:
html = '<p><span class="map-sub-title">abc</span>123</p>'
soup1 = BeautifulSoup(html,"lxml")
p = soup1.text
我要求的只是:S3.getObject(params).promise()
.then((configYaml) => {
// Get the content of the file as a string
// It works on any text file, should your config is in another format
const data = configYaml.Body.toString('utf-8');
console.log(data);
// Parse the string, which is a yaml in this case
// Please note that `YAML.parse()` is deprecated
return YAML.load(data);
})
.then((config) => {
// Do some wonderful staff with the config object
console.log(`• Config: ${JSON.stringify(config)}`);
return null;
})
.then(callback)
.catch(callback);
。