0

I (try to) deploy my current application using CDK pipelines.

In doing so, I stumbled across an unexpected behavior (here if interested) which now I am trying to resolve. I have a Lambda function for which the asset is a directory that is dynamically generated during a CodeBuild step. The line is currently defined like this in my CDK stack :

code: lambda.Code.fromAsset(process.env.CODEBUILD_SRC_DIR_BuildLambda || "")

The issue is that locally, this triggers the unexpected and undesired behaviour because the environment variable does not exist and therefore goes to the default "".

What is the proper way to avoid this issue?

Thanks!

1 Answer 1

1

Option 1: Set the env var locally, pointing to the correct source directory;

CODEBUILD_SRC_DIR_BuildLambda=path/to/lambda && cdk deploy

Option 2: Define a dummy asset if CODEBUILD_SRC_DIR_BuildLambda is undefined

code: process.env.CODEBUILD_SRC_DIR_BuildLambda
  ? lambda.Code.fromAsset(process.env.CODEBUILD_SRC_DIR_BuildLambda)
  : new lambda.InlineCode('exports.handler = async () => console.log("NEVER")'),
Sign up to request clarification or add additional context in comments.

4 Comments

Yeah that is one possibility. I was just wondering how ‘state of the art’ this is.
@FenryrMKIII This problem does not arise in CDK "state of the art", because Infrastructure and runtime code live in the same package.
Yes, I have seen this article. But in my business case, we work with contractors and they have the repo for the application while we own the repo for the infra. So how should we do? Use GitHub submodule capacities to reach this situation of one repo for infra and code ?
@FenryrMKIII It's OK for atypical use cases like yours to deviate from "best practices", which are for standard scenarios. I was just answering the questions as written.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.