Skip to content

Commit

Permalink
feat(cli): adds flags to image lambda and API domain customization
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiob authored and sladg committed Jan 3, 2023
1 parent 2f724a8 commit f4920f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -53,12 +57,15 @@ program
.option('--bootstrap', 'Bootstrap CDK stack.', false)
.option('--lambdaTimeout <sec>', 'Set timeout for lambda function handling server requirests.', Number, 15)
.option('--lambdaMemory <mb>', 'Set memory for lambda function handling server requirests.', Number, 512)
.option('--imageLambdaTimeout <sec>', 'Set timeout for lambda function handling image optimization.', Number, IMAGE_LAMBDA_DEFAULT_TIMEOUT)
.option('--imageLambdaMemory <mb>', 'Set memory for lambda function handling image optimization.', Number, IMAGE_LAMBDA_DEFAULT_MEMORY)
.option('--hostedZone <domainName>', 'Hosted zone domain name to be used for creating DNS records (example: example.com).', undefined)
.option('--domainNamePrefix <prefix>', 'Prefix for creating DNS records, if left undefined, hostedZone will be used (example: app).', undefined)
.option('--customApiDomain <domain>', '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)
8 changes: 7 additions & 1 deletion lib/cli/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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) {
Expand Down

0 comments on commit f4920f8

Please sign in to comment.