Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save leegilmorecode/b5a36a1758f830d6f484e4e659cb4a18 to your computer and use it in GitHub Desktop.
Example of pulling the files from S3
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