Skip to content

Instantly share code, notes, and snippets.

@leegilmorecode
Created July 31, 2021 14:19
Show Gist options
  • Select an option

  • Save leegilmorecode/43f637253d645a2ab70f4079991494a7 to your computer and use it in GitHub Desktop.

Select an option

Save leegilmorecode/43f637253d645a2ab70f4079991494a7 to your computer and use it in GitHub Desktop.
Example of pulling the files from EFS within a lambda function
import { APIGatewayProxyHandler, APIGatewayProxyResult } from 'aws-lambda';
import { getFilesFromFolder } from '../shared/get-files-from-folder/get-files-from-folder';
import { sortFiles } from '../shared/sort-files/sort-files';
import { config } from '../shared/config/config';
import FileObject from '../shared/types/FileObject';
export const handler: APIGatewayProxyHandler = async (): Promise<APIGatewayProxyResult> => {
try {
console.log(`Get the files from the efs folder ${config.efsMountPath}`);
const files: FileObject[] = await getFilesFromFolder(config.fileKeys, config.efsMountPath);
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(
{
files: sortFiles(files),
},
null,
2,
),
};
} catch (error: any) {
console.error(error);
return {
statusCode: 500,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify('An error has been generated', null, 2),
};
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment