--no-optional-dependencies
async function zipData(content: string): Promise<Buffer> {
return new Promise((resolve, reject) => {
const filename = `/tmp/${new Date().valueOf()}.zip`;
const dataBuffer = Buffer.alloc(content.length, content);
const output = fs.createWriteStream(filename);
const archive = Archiver('zip', {
zlib: { level: 9 },
});
output.on('close', () => {
async function asyncWorker(): Promise<Buffer> {
return await readFileAsync(filename);
}
asyncWorker()
.then((output) => {
return resolve(output);
})
.catch((err) => {
return reject(err);
});
});
archive.on('error', (err) => {
log.error('zipping archive error', err);
return reject(err);
});
archive.pipe(output);
archive.append(dataBuffer, { name: 'data.csv' });
archive.finalize();
});
}
#!/usr/bin/env bash
mkdir -p ~/.aws
cat > ~/.aws/credentials << EOF
[deploy]
aws_access_key_id=$AWS_ACCESS_KEY_ID
aws_secret_access_key=$AWS_SECRET_ACCESS_KEY
EOF
export AWS_PROFILE=deploy
./node_modules/.bin/claudia update --no-optional-dependencies --version live
validating package npm dedupe -q --no-package-lock
npm ERR! code EEXIST
npm ERR! Refusing to delete /tmp/LADlqq/xxx/package/node_modules/claudia/node_modules/.bin/mkdirp: is outside /tmp/LADlqq/xxx/package/node_modules/claudia/node_modules/mkdirp and not a link
claudia update --source dist --handler scripts/lambda.handler --use-local-dependencies --role api-deployment-executor --use-s3-bucket lambda-uploads --memory 1024 --timeout 300 --deploy-proxy-api --region eu-central-1 --config bin/deploy/claudia-dev.json --name app-api-staging
if (isLambda) {
// You're on AWS Lambda
module.exports = app;
} else {
// Local or elsewhere
app.listen(3000);
}
index.js does not export method handler
If you want to have your app in AWS Lambda fast, deploy your express app directly, then start splitting it.
There are many benefits. Smaller apps are faster (you probably heard about cold start, it almost doesn’t not exist with small lambdas). It’s easier to debug (logs will be separated by routes)...