Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions source/image-handler/src/image-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export class ImageRequest {
CacheControl: any;
ETag: any;
headers: any;
private s3: any;
request_id: any;
accept: any;
private s3?: S3;

constructor(s3: S3) {
this.s3 = s3;
Expand Down Expand Up @@ -87,6 +89,9 @@ export class ImageRequest {
}
}

this.request_id = event.headers['X-Amz-Cf-Id'];
this.accept = event.headers.Accept || event.headers.accept;

delete this.s3;

return this;
Expand All @@ -101,7 +106,7 @@ export class ImageRequest {
async getOriginalImage(bucket: string, key: string): Promise<any> {
const imageLocation = { Bucket: bucket, Key: key };
try {
const originalImage: GetObjectCommandOutput = await this.s3.getObject(imageLocation);
const originalImage: GetObjectCommandOutput = await this.s3!.getObject(imageLocation);
const metaData = originalImage['Metadata'];
const isGone = metaData && metaData['buzz-status-code'] && metaData['buzz-status-code'] === '410';

Expand Down Expand Up @@ -310,7 +315,7 @@ export class ImageRequest {
getOutputFormat(event: APIGatewayProxyEventV2): keyof sharp.FormatEnum | null {
const autoWebP = process.env.AUTO_WEBP;
const autoAvif = process.env.AUTO_AVIF;
let accept = (event.headers?.Accept || event.headers?.accept) ?? '';
let accept = event.headers?.Accept || event.headers?.accept;
if (autoAvif === 'Yes' && accept && accept.includes('image/avif')) {
return 'avif';
} else if (autoWebP === 'Yes' && accept && accept.includes('image/webp')) {
Expand Down
3 changes: 2 additions & 1 deletion source/image-handler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export async function handler(event: APIGatewayProxyEventV2): Promise<APIGateway

try {
const request: ImageRequest = await imageRequest.setup(event);
logger.info('Image manipulation request', { ...request, originalImage: undefined });
logger.appendKeys({ ...request, originalImage: undefined });
logger.info('Image manipulation request');

let now = Date.now();
if (request.Expires && request.Expires.getTime() < now) {
Expand Down
4 changes: 0 additions & 4 deletions source/image-handler/src/lib/logging/LogStashFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class LogStashFormatter extends LogFormatter {
service: attributes.serviceName,
environment: attributes.environment,
awsRegion: attributes.awsRegion,
correlationIds: {
awsRequestId: attributes.lambdaContext?.awsRequestId,
xRayTraceId: attributes.xRayTraceId,
},
lambdaFunction: {
name: attributes.lambdaContext?.functionName,
arn: attributes.lambdaContext?.invokedFunctionArn,
Expand Down