This message was deleted.
# general
s
This message was deleted.
w
You mean post to another http endpoint inside a JavaScript runtime function? If so -
axios
,
fetch
or
request
are simple options (on NPM).
d
I tried fetch, but got some kind of serialization error. I'll try axios
tried axios, got a different serialization error:
Copy code
error: Error serializing '(event) => __awaiter(this, void 0, v ...': index.js(77,68)
    
    '(event) => __awaiter(this, void 0, v ...': index.js(77,68): captured
      module './node_modules/axios/index.js' which indirectly referenced
        function 'wrap': bind.js(4,22): which captured
          'fn', a function defined at
            function 'request': Axios.js(26,42): which captured
              module './node_modules/axios/lib/defaults.js' which indirectly referenced
                function 'httpAdapter': http.js(17,37): which captured
                  module 'url' which indirectly referenced
                    function 'urlParse': url.js(96,17): which referenced
                      function 'Url': url.js(44,12): which referenced
                        function 'parse': url.js(104,36): which captured
                          variable 'errors' which indirectly referenced
                            function 'NodeError': errors.js(24,15): which referenced
                              function 'message': errors.js(103,16): which captured
                                variable 'messages' which indirectly referenced
                                  function 'get': which could not be serialized because
                                    it was a native code function.
    
    Function code:
      function get() { [native code] }
    
    Capturing modules can sometimes cause problems.
    Consider using import('./node_modules/axios/index.js') or require('./node_modules/axios/index.js') inside '(event) => __awaiter(this, void 0, v ...': index.js(77,68)
 
    error: an unhandled error occurred: Program exited with non-zero exit code: 1
 
error: an error occurred while advancing the preview
w
Until we release
0.15.0
(should be Monday), you will need to import
axios
inside your function:
Copy code
let f = new aws.Serverless.Function("f", { ...}, async (ev, ctx) => {
  let axios = await import("axios"); // or let axios = require("axios");
});
With
0.15.0
you will be able to import ant the top of the file and use inside runtime functions. cc @lemon-spoon-91807
👍 1
d
d'oh ok thanks
l
let us know if you run into any problems with that!
this should hopefully give a really nice development experience around using modules.
ideally, you shouldn't have to think about it at all... (hopefully) 🙂
d
can I get a typed version of
axios
this way somehow?
l
prior to 15.0 you mean?
w
let axios = await import("axios");
will bring in types.
d
ideally, but OK if the answer is "later" 🙂
l
pre 15.0 you can use: let axios = await import("axios");
axios will be strongly typed
if you need to use a type from axios (i.e. for a signature)
d
ah got it. had to do
.default
l
ah
d
got it - thanks guys
l
if you need to use a type, there's a way to do it, but it's a bit complex. so i'll only post it if you need it 🙂
great!