aws / aws/aws-toolkit-visual-studio
Lambda Container Relative Path to Custom Code File
- Dominant language
- No language data
- Stars
- 135
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
I've tried this a hundred different ways but I can't understand what I'm doing wrong. I have an app.js file from the base container image nodejs14.x-v1 from AWS. I use the toolkit to build the image and deploy to an ECR that automatically creates the lambda function. Everything works fine if when I have all of my code loaded in the app.js file: angular app -> submit JSON to API Gateway -> API Gateway invokes Lambda -> Lambda connects to Mongo Atlas cluster and saves the object. This all works when the code is loaded from a single file.
When I abstract the Schema and Mongo connection into other files in the same folder as app.js, require('./filename') is wrong. I've tried /var/task, I've tried copying all relavent files over to both ./ and /var/task to make sure they're in the same path as app.js. I feel like it's something ridiculously simple and nothing to do with toolkit but I'm hoping someone here can help me understand what I'm doing wrong.
DOCKERFILE: -------------------------------------
FROM public.ecr.aws/lambda/nodejs:14
ARG FUNCTION_DIR="/var/task"
# Create function directory
RUN mkdir -p ${FUNCTION_DIR}
# Copy handler function and package.json
COPY app.js ${FUNCTION_DIR}
COPY package.json ${FUNCTION_DIR}
COPY mongoconnection.js ${FUNCTION_DIR}
COPY assetSchema.js ${FUNCTION_DIR}
# Install NPM dependencies for function
RUN npm install
# Command can be overwritten by providing a different command in the template directly.
CMD ["app.lambdaHandler"]
app.js requires ---------------------------------------
// import asset Schema
const schema = require('./assetSchema.js');
// import connection helper
const conn = require('./mongooseconnection.js');
Contributor guide
Research direction
Compare the filenames copied in the Dockerfile with the paths required in app.js, especially mongoconnection.js versus mongooseconnection.js. Start by checking the built container’s /var/task contents and whether each require path resolves; done means the Lambda handler can load both helper files and run successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, docker, node.js
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100