Created
July 31, 2021 14:19
-
-
Save leegilmorecode/43f637253d645a2ab70f4079991494a7 to your computer and use it in GitHub Desktop.
Example of pulling the files from EFS within a lambda function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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