Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from pwrdrvr/setup-test-framework
Browse files Browse the repository at this point in the history
Setup test framework
  • Loading branch information
huntharo committed Dec 4, 2021
2 parents b6c9029 + ec114f1 commit 5d90aa0
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 76 deletions.
15 changes: 5 additions & 10 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,14 @@ const project = new TypeScriptProject({
'@rollup/plugin-node-resolve@^11.2.0',
'@types/aws-lambda@^8.10.72',
'@types/lambda-log@^2.2.0',
'aws-sdk-client-mock@^0.5.6',
'rollup@^2.39.0',
'rollup-plugin-node-externals@^2.2.0',
'rollup-plugin-terser@^7.0.2',
'rollup-plugin-typescript2@^0.30.0',
],

deps: [
'@aws-sdk/client-s3@^3.32.0',
'@aws-sdk/middleware-retry@^3.32.0',
'@aws-sdk/smithy-client@^3.32.0',
'get-stream@^6.0.0',
'lambda-log@^2.4.0',
],
deps: ['@aws-sdk/client-s3@^3.32.0', 'get-stream@^6.0.0', 'lambda-log@^2.4.0'],

// scripts: {
// 'compile': 'rollup --config && tsc -p tsconfig.build.json',
Expand Down
107 changes: 107 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export async function handler(

// Fall through to S3
const cfEvent = apigwyEventTocfRequestEvent('origin-request', event, config);
const s3Response = await fetchFromS3(cfEvent.Records[0].cf.request, config);
const s3Response = await fetchFromS3(cfEvent.Records[0].cf.request, config, log);

decodeResponse(s3Response);

Expand Down Expand Up @@ -121,13 +121,15 @@ export async function handler(

// Convert API Gateway Request to Origin Request
const cfEvent = apigwyEventTocfRequestEvent('origin-request', event, config);
log.info('apigwyEvent translated to CF Request', { event, cfEvent });
const imageImport = './image-lambda';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const imageHandler = await import(imageImport);
//const imageHandler = (await import(imageImport)).handler;
const cfRequestResponse = await imageHandler.handler(
cfEvent as lambda.CloudFrontRequestEvent,
);
log.info('apigwyEvent imageHandle response', { cfRequestResponse });

// TODO: Do we ever need to proxy to s3 or does imageHandler always do it?
// 2021-03-06 - Image optimizer does not currently save back to s3,
Expand All @@ -141,7 +143,10 @@ export async function handler(
}

// Translate the CF Response to API Gateway response
return cfResponseToapigwyResponse(cfRequestResponse);
const apigwyResponse = cfResponseToapigwyResponse(cfRequestResponse);
log.info('apigwyEvent imageHandle response', { apigwyResponse });

return apigwyResponse;
} else {
log.options.meta = { ...log.options.meta, route: 'default' };
log.info('default route');
Expand All @@ -162,15 +167,15 @@ export async function handler(
return cfResponseToapigwyResponse(cfRequestResponse);
}

log.debug('got response from request handler', { cfRequestResult });
log.info('got response from request handler', { cfRequestResult });

log.info('falling through to s3');

// No response was generated; call the s3 origin then call the response handler
const cfRequestForOrigin = cfRequestResult as unknown as lambda.CloudFrontRequest;

// Fall through to S3
const s3Response = await fetchFromS3(cfRequestForOrigin, config);
const s3Response = await fetchFromS3(cfRequestForOrigin, config, log);

log.debug('got response from s3', { s3Response });

Expand Down
4 changes: 2 additions & 2 deletions src/lib/apigwyToCF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export function apigwyEventTocfRequestEvent(
},
domainName: config.s3BucketName,
// We use AWS_REGION env var instead
region: 'dummy',
// region: config.s3.region,
// region: 'dummy',
region: config.region,
path: '',
// CF uses OAI to access S3 from Lambda @ Edge
// But from Lambda we can just have IAM privs to get/put
Expand Down
28 changes: 0 additions & 28 deletions src/lib/retryStrategy.ts

This file was deleted.

Loading

0 comments on commit 5d90aa0

Please sign in to comment.