Skip to content

Instantly share code, notes, and snippets.

@Bnaya
Last active December 13, 2020 11:28
Show Gist options
  • Save Bnaya/946c89d4060f1aa5a20204c18934471c to your computer and use it in GitHub Desktop.
Save Bnaya/946c89d4060f1aa5a20204c18934471c to your computer and use it in GitHub Desktop.
Lambda + api gateway + CF = serve zip
# package directories
node_modules
jspm_packages
# Serverless directories
.serverless

Lambda + api gateway + CF = serve zip

'use strict';
const path = require('path');
module.exports.hello = async event => {
try {
const fs = require('fs');
const fileContents = await new Promise((res, rej) => {
fs.readFile(path.resolve(__dirname, 'thiswillbezipcontent.txt.zip'), (err, data) => {
if (err) {
rej(err)
} else {
res(data)
}
});
});
return {
statusCode: 200,
body: fileContents.toString('base64'),
headers: {
'Content-Type': 'application/zip'
},
isBase64Encoded: true
};
} catch (e) {
return {
statusCode: 200,
body: `can't read: ${e.message}`,
}
}
};
service: serve-zip-file
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x
apiGateway:
binaryMediaTypes:
- '*/*'
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: get
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment