Issue Loading AWS SDK for CloudFront Invalidation in Retool

Hi,

I have enabled CloudFront to improve the file fetching speed from S3. However, I'm facing an issue when trying to run an invalidation query in CloudFront after deleting a file from S3.

Steps Taken:

  1. Enabled CloudFront: Configured CloudFront to speed up file retrieval from S3.
  2. CORS Configuration: Configured the CORS policy for my S3 bucket as follows:
    [
        {
            "AllowedHeaders": ["*"],
            "AllowedMethods": ["PUT", "POST", "DELETE"],
            "AllowedOrigins": ["https://*.retool.com"],
            "ExposeHeaders": []
        },
        {
            "AllowedHeaders": [],
            "AllowedMethods": ["GET"],
            "AllowedOrigins": ["*"],
            "ExposeHeaders": []
        }
    ]
    

Problem:
To run the invalidation query in CloudFront for the deleted file, I need to load the AWS SDK. However, I am encountering issues with loading the SDK in Retool due to CORS policy restrictions.

Steps Tried:

  1. Using CDN URL:

    • Added https://sdk.amazonaws.com/js/aws-sdk-2.880.0.min.js to the JavaScript Libraries in Retool.
    • Resulted in a CORS policy error: No 'Access-Control-Allow-Origin' header is present on the requested resource.
  2. Alternative CDN:

    • Tried using https://cdn.jsdelivr.net/npm/aws-sdk@2.880.0/dist/aws-sdk.min.js.
    • Still faced similar CORS issues.
  3. Direct Embedding:

    • Attempted to directly include the contents of aws-sdk.min.js in a JavaScript query within Retool.
    • Encountered issues with script execution and no logs indicating the AWS SDK was loaded.

Could you please provide guidance on how to correctly load the AWS SDK in Retool to run the CloudFront invalidation query? Any help to resolve the CORS issues or alternative methods to achieve this would be greatly appreciated.

Thanks in advance.

1 Like

Hey @nizaeros! I think I found a solution for you - can you try using this CDN instead: https://cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.1664.0/aws-sdk.min.js? I tried it out on a Cloud instance and it seems to work. The only potential issue is that its version isn't recent enough, but it seems to support CloudFront. :slight_smile:

In general, we recommend searching for minified CDNs on cdnjs, as they seem to have the greatest compatibility with Retool's custom libraries functionality.

I hope that helps! Don't hesitate to follow up here if you run into any other issues.

1 Like

thank youuuuu

1 Like