У меня есть AWS безсерверное приложение с узлом и graphql. handelr. js как показано ниже
'use strict';
const { graphql } = require('graphql');
const schema = require('../schema/schema.js');
module.exports.query = (event, context, callback) =>
graphql(schema, event.queryStringParameters.query).then(
result => callback(null, { statusCode: 200, body: JSON.stringify(result) }),
err => callback(err)
);
Мне нужен доступ к деталям хоста Cloudfront для отправки предопределенного URL,
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
signedUrl: {
args: {
fileName: { name: 'fileName', type: new GraphQLNonNull(GraphQLString) },
fileType: { name: 'fileType', type: new GraphQLNonNull(GraphQLString) },
},
type: GraphQLString,
resolve: (parent, args) => getSignedUrl(args.fileName, args.fileType),
},
},
}),
Функция getSignedUrl, как показано ниже,
const getSignedUrl = (fileName, fileType) => {
const signedUrl = s3.getSignedUrl('putObject', {
Bucket: bucket,
Key: fileName,
});
const { path } = url.parse(signedUrl);
const hash = crypto
.createHash('sha256')
.update(path)
.digest('hex');
await s3
.putObject({
Bucket: bucket,
Key: `signatures/valid/${hash}`,
Body: JSON.stringify({ created: Date.now() }),
ContentType: 'application/json',
ContentEncoding: 'gzip',
})
.promise();
const response = {
status: '200',
statusDescription: 'OK',
headers: {
'content-type': [
{
key: 'Content-Type',
value: 'text/plain',
},
],
'content-encoding': [
{
key: 'Content-Encoding',
value: 'UTF-8',
},
],
},
body: `https://${host}${path}`,
};
};
Я следую https://serverless.com/blog/s3-one-time-signed-url/ учебному пособию, и в нем приведен код ниже для доступа к хосту облачного фронта из деталей события,
exports.handler = async event => {
const { request } = event.Records[0].cf;
const { headers } = request;
const host = headers.host[0].value;
У меня проблема с тем, как получить подробности облачного фронта из событие graphql.