relative import resolution error with transpiled TypeScript code in Lambda with container images

0

I'm trying to get started developing a lambda function via typescript.

I've following the instructions here to set up my project: https://docs.aws.amazon.com/lambda/latest/dg/typescript-image.html

The example code given at the link above builds and runs just fine.

But when I modify the code as follows, the build step fails:

  1. I add a file schema.ts in the project's root directory that exports an object like this:
export const ValidRequestObject = {sessionId: 2}
  1. In index.ts I add `import { ValidRequestObject } from './schema'.

Running docker build --platform linux/amd64 -t docker-image:test . now fails. Here's the error:

0.730 ✘ [ERROR] Could not resolve "./schema"
0.730
0.730     index.ts:2:30:
0.730       2 │ import { ValidRequestObject } from './schema';
0.730         ╵                               ~~~~~~~~~~
0.730

To be clear, the above are the ONLY modifications I've made to the example in the documentation linked above.

So I guess the question is: What do I need to do to make relative imports work at the build step?

asked 4 months ago253 views
1 Answer
0

So the dockerfile suggested by the aws documentation I followed has the line

COPY package.json index.ts ./

I would expect that the ./ part of this would cause every file in the project directory to be copied over to the container.

Apparently not. The problem was fixed by manually adding the file from which index.ts was importing to that line like so:

COPY package.json index.ts schema.ts ./

Although this fixes the problem, I'm still not sure how to cause all the files in the project directory (excepting of course .gitignore) to get copied over to the container before the build step without having to manually write their names into the COPY line as above. If anyone knows, please tell me.

answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions