Hi, I’m trying to implement a custom dynamic prov...
# typescript
m
Hi, I’m trying to implement a custom dynamic provider to upload files to S3. I’m currently stuck with this error:
Copy code
error: Error serializing '() => provider': index.js(28,47)

    '() => provider': index.js(28,47): captured
      variable 'provider' which indirectly referenced
        function 'S3UploadResourceProvider': s3Upload.ts(77,15): which referenced
          function 'create': s3Upload.ts(138,10): which referenced
            function 'uploadDirectoryToS3': s3Upload.ts(58,28): which referenced
              function 'getFiles': s3Upload.ts(28,17): which captured
                variable 'promises_1' which indirectly referenced
                  function 'readdir': which referenced
                    function 'getOptions': which captured
                      'ERR_INVALID_ARG_TYPE', a function defined at
                        function 'NodeError': which referenced
                          function 'isErrorStackTraceLimitWritable': which captured
                            'ObjectGetOwnPropertyDescriptor', a function defined at
                              function 'getOwnPropertyDescriptor': which could not be serialized because
                                it was a native code function.

    Function code:
      function getOwnPropertyDescriptor() { [native code] }
Would appreciate any ideas on how to work around this 🙂
b
hey there, could you share your code?
also, are you aware of the bucket object resource? 😄
m
hey, thanks for looking into it! attaching the relevant code. the intention is to make atomic deploys possible with cloudfront + s3, so i can’t use the bucket object resource, bc that’ll delete the old files during deployment. the solution i came up with here is this custom dynamic resource that just uploads files to a prefix on s3 and i set the prefix as the origin path in cloudfront. it never deletes or updates files.
node version 16.9.1 btw
b
hmm I don't see anything at first glance I'm afraid, i'll try get someone smarter to have a look
m
thanks! i’ll be off for the weekend now — back on Tuesday
c
We have a library which does this https://github.com/sevenwestmedia-labs/pulumi-components/tree/main/libs/throw-files-in-s3 It works a bit differently but you can use it as a reference
m
Thanks @curved-pharmacist-41509 your code gave me an idea to work around the issue: turns out that replacing promisifed readdir with the sync version makes it run. @billowy-army-68599 I’ve added a reproducible bug report here: https://github.com/pulumi/pulumi/issues/8090