Created
July 31, 2021 14:10
-
-
Save leegilmorecode/b5a36a1758f830d6f484e4e659cb4a18 to your computer and use it in GitHub Desktop.
Example of pulling the files from S3
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 { getImagesFromBucket } from '../shared/get-images-from-bucket/get-images-from-bucket'; | |
| 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 s3 bucket ${config.bucketName}`); | |
| const files: FileObject[] = await getImagesFromBucket(config.bucketName, config.fileKeys); | |
| 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