From f4920f81f4a6e11e15213ead32c4eba4aa2aa9b7 Mon Sep 17 00:00:00 2001 From: Fabio Batista Date: Tue, 3 Jan 2023 00:22:03 -0300 Subject: [PATCH] feat(cli): adds flags to image lambda and API domain customization --- lib/cli.ts | 11 +++++++++-- lib/cli/deploy.ts | 8 +++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/cli.ts b/lib/cli.ts index 0245423..8fea79a 100644 --- a/lib/cli.ts +++ b/lib/cli.ts @@ -6,6 +6,10 @@ import packageJson from '../package.json' import { deployHandler } from './cli/deploy' import { packHandler } from './cli/pack' import { wrapProcess } from './utils' +import { + DEFAULT_TIMEOUT as IMAGE_LAMBDA_DEFAULT_TIMEOUT, + DEFAULT_MEMORY as IMAGE_LAMBDA_DEFAULT_MEMORY, +} from './cdk/utils/imageLambda' const commandCwd = process.cwd() const program = new Command() @@ -53,12 +57,15 @@ program .option('--bootstrap', 'Bootstrap CDK stack.', false) .option('--lambdaTimeout ', 'Set timeout for lambda function handling server requirests.', Number, 15) .option('--lambdaMemory ', 'Set memory for lambda function handling server requirests.', Number, 512) + .option('--imageLambdaTimeout ', 'Set timeout for lambda function handling image optimization.', Number, IMAGE_LAMBDA_DEFAULT_TIMEOUT) + .option('--imageLambdaMemory ', 'Set memory for lambda function handling image optimization.', Number, IMAGE_LAMBDA_DEFAULT_MEMORY) .option('--hostedZone ', 'Hosted zone domain name to be used for creating DNS records (example: example.com).', undefined) .option('--domainNamePrefix ', 'Prefix for creating DNS records, if left undefined, hostedZone will be used (example: app).', undefined) + .option('--customApiDomain ', 'Domain to forward the requests to /api routes, if left undefined, API routes will be handled by the server lambda.', undefined) .action(async (options) => { console.log('Our config is: ', options) - const { stackName, appPath, bootstrap, lambdaTimeout, lambdaMemory, hostedZone, domainNamePrefix } = options - wrapProcess(deployHandler({ stackName, appPath, bootstrap, lambdaTimeout, lambdaMemory, hostedZone, domainNamePrefix })) + const { stackName, appPath, bootstrap, lambdaTimeout, lambdaMemory, imageLambdaMemory, imageLambdaTimeout, hostedZone, domainNamePrefix, customApiDomain } = options + wrapProcess(deployHandler({ stackName, appPath, bootstrap, lambdaTimeout, lambdaMemory, imageLambdaMemory, imageLambdaTimeout, hostedZone, domainNamePrefix, customApiDomain })) }) program.parse(process.argv) diff --git a/lib/cli/deploy.ts b/lib/cli/deploy.ts index 2b598dd..83be1c7 100644 --- a/lib/cli/deploy.ts +++ b/lib/cli/deploy.ts @@ -6,13 +6,16 @@ interface Props { bootstrap: boolean lambdaMemory?: number lambdaTimeout?: number + imageLambdaMemory?: number + imageLambdaTimeout?: number + customApiDomain?: string hostedZone?: string domainNamePrefix?: string } const cdkExecutable = require.resolve('aws-cdk/bin/cdk') -export const deployHandler = async ({ stackName, appPath, bootstrap, lambdaMemory, lambdaTimeout, domainNamePrefix, hostedZone }: Props) => { +export const deployHandler = async ({ stackName, appPath, bootstrap, lambdaMemory, lambdaTimeout, imageLambdaMemory, imageLambdaTimeout, domainNamePrefix, hostedZone, customApiDomain }: Props) => { // All paths are absolute. const cdkApp = `node ${appPath}` const cdkCiFlags = `--require-approval never --ci` @@ -21,8 +24,11 @@ export const deployHandler = async ({ stackName, appPath, bootstrap, lambdaMemor STACK_NAME: stackName, ...(lambdaMemory && { LAMBDA_MEMORY: lambdaMemory.toString() }), ...(lambdaTimeout && { LAMBDA_TIMEOUT: lambdaTimeout.toString() }), + ...(imageLambdaMemory && { IMAGE_LAMBDA_MEMORY: imageLambdaMemory.toString() }), + ...(imageLambdaTimeout && { IMAGE_LAMBDA_TIMEOUT: imageLambdaTimeout.toString() }), ...(hostedZone && { HOSTED_ZONE: hostedZone }), ...(domainNamePrefix && { DNS_PREFIX: domainNamePrefix }), + ...(customApiDomain && { CUSTOM_API_DOMAIN: customApiDomain }), } if (bootstrap) {