https://serverless-stack.com/ logo
#sst
Title
# sst
a

Adrián Mouly

12/22/2021, 8:05 PM
Hey guys, I’m using
DockerImageFunction
construct from CDK into my SST stack. How can I test this locally? Can I run the docker image locally? and how I can connect to Dynamo and others? is that possible from LOCAL?
t

thdxr

12/22/2021, 8:05 PM
We currently don't support docker functions for local debugging
a

Adrián Mouly

12/22/2021, 8:06 PM
I know, but apart from SST.
Is there a workaround? or how should I test it?
t

thdxr

12/22/2021, 8:10 PM
ah sorry misread
It's pretty hard to test it by spinning up the image, I'd test theu nderlying code it's calling from outside docker
a

Adrián Mouly

12/22/2021, 8:11 PM
So I’m running python functions in docker.
Maybe I can just test the python code, somehow.
d

Derek Kershner

12/22/2021, 9:11 PM
By
test
, do you mean unit test? It sounds more like you mean running a local dev environment, in which case I believe the answer will depend how the lambda is invoked.
a

Adrián Mouly

12/22/2021, 9:11 PM
Test I mean... Human test, the developer invoking it.
d

Derek Kershner

12/22/2021, 9:13 PM
whats the trigger?
and you should be really sure whatever you are trying to do cant be handled in unit tests, its gonna be unpleasant, lol
for most triggers, id just pull the handler into a file, run it with whatever variables you want, and execute the file with
AWS_PROFILE
env variable populated
this is essentially a unit test, but no stubs
s

Simon Reilly

12/22/2021, 9:49 PM
You can test it locally with the runtime interface operator How to do this using curl is in the official docs https://docs.aws.amazon.com/lambda/latest/dg/images-create.html For including dynamodb you could do further local emulation. Or use something like wiremock or robohydra to perform intercepts. I do wonder though if ultimately testing in aws will be easier?
d

Derek Kershner

12/22/2021, 10:34 PM
I do wonder though if ultimately testing in aws will be easier?
I think so. https://dev.to/garethmcc/why-local-development-for-serverless-is-an-anti-pattern-1d9b
there is a reason why SST is so awesome 😉