I previously asked this question and got a solution to expanding arguments in a dockerfile.
Expand ARG/ENV in CMD dockerfile
I think with AWS Lambdas the handler name has to be the first argument. I have a parameterized jenkins pipeline that takes in a parameter named LAMBDA_NAME and I append the handler to it.
When I hard-code the lambda name, there are no issues.
ARG LAMBDA_NAME
ENV LAMBDA_HANDLER="${LAMBDA_NAME}.handler"
RUN echo "${LAMBDA_HANDLER}"
CMD [ "sourceproducer.handler" ]
But what I am looking to do is to use the LAMBDA_HANDLER variable above. When echo is called it correctly spits out "sourceproducer.handler"
At first, I tried to run it in exec form and ran into this issue ([ERROR] Runtime.MalformedHandlerName: Bad handler '${LAMBDA_HANDLER}': not enough values to unpack (expected 2, got 1)
ARG LAMBDA_NAME
ENV LAMBDA_HANDLER="${LAMBDA_NAME}.handler"
RUN echo "${LAMBDA_HANDLER}"
CMD [ "${LAMBDA_HANDLER}" ]
The question answered above, said to use exec form instead, so I tried both of these ways of running it
CMD "${LAMBDA_HANDLER}"
And
CMD [ "/bin/sh", "-c", "${LAMBDA_HANDLER}" ]
However, now because I am using exec form "/bin/sh" is the first argument and it doesn't conform with AWS Lambda wanting the handler as the first argument.
I thought perhaps switching the order of the arguments would help, but it didn't.
CMD ["${LAMBDA_HANDLER}", "/bin/sh", "-c" ]
So, the question is how do I pass in LAMBDA_HANDLER argument AND have it be the first argument? Use entrypoint or custom shell script? Open to ideas about the approach