Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only in Production - downloadDate and getUrl return "public/undefined" Signed URL, all other environments work even dev -> prod s3 bucket #14227

Open
3 tasks done
GrahamEvans31 opened this issue Feb 20, 2025 · 7 comments
Labels
investigating This issue is being investigated question General question Storage Related to Storage components/category

Comments

@GrahamEvans31
Copy link

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Storage

Amplify Version

v6

Amplify Categories

storage

Backend

Other

Environment information

aws-amplify latest
Netlify

Everything runs correctly locally and even in the Netlify development website but when it makes it into production it fails. Development can access production S3 just fine but in production no access to production s3 bucket.

Describe the bug

When developing, I can access any S3 bucket either my dev or prod, no issues and correct signed URLs are generated. When I deploy into my Netlify dev. environment, same, not issues it works correctly. When my code is in production on a app.v2. endpoint, it is a subdomain not sure if there's a CORS issue here I tried many S3 bucket permissions changes trying to understand what potential environment differences. I generated production builds and ran them locally as well, these work fine locally but when the code is deployed into production, every call to generate a URL returns something like:

https://prod-rynsemedia.s3.us-west-2.amazonaws.com/public/undefined

even when I hardcode the input path, it returned this "undefined" URL. At first it said s3:ListBucket was not allowed, but it did work from all other environments including directly to this prod-rynsemedia bucket. I added the s3:ListBucket to the prod bucket and then the error for ListBucket disappeared but it still generated the '/undefined' URL and would say 404 object does not exist. I am unable to get either downloadData or getUrl to return correct URL's ONLY in the production environment hosted in Netlify. I've checked all environment variables, these are correct, there is almost no way for me to debug this issue that I can think of but it seems to be an issue within the aws-amplify code that is a silent error or sorts.

Expected behavior

Generate the correct signed URL location, not an "undefined"

Reproduction steps

Only in netlify production environment is an "undefined" URL location returned.

Code Snippet

  const downloadResult = await downloadData({
    path: `public/metrics/....json` //Even hard coded location will return 'public/undefined'
  }).result;

Log output

index-DGZZhei7.js:792 
        
        
       GET https://<bucket>.s3.us-west-2.amazonaws.com/public/undefined 404 (Not Found)
(anonymous) @ index-DGZZhei7.js:792
xhrTransferHandler @ index-DGZZhei7.js:792
nu @ index-DGZZhei7.js:455
(anonymous) @ index-DGZZhei7.js:458
await in (anonymous)
(anonymous) @ index-DGZZhei7.js:455
(anonymous) @ index-DGZZhei7.js:455
(anonymous) @ index-DGZZhei7.js:792
await in (anonymous)
(anonymous) @ index-DGZZhei7.js:455
(anonymous) @ index-DGZZhei7.js:455
await in (anonymous)
(anonymous) @ index-DGZZhei7.js:793
await in (anonymous)
(anonymous) @ index-DGZZhei7.js:793
createCancellableTask @ index-DGZZhei7.js:793
downloadData @ index-DGZZhei7.js:793
(anonymous) @ index-DGZZhei7.js:793
(anonymous) @ index-DGZZhei7.js:793
Rj @ index-DGZZhei7.js:43
Ik @ index-DGZZhei7.js:43
Xk @ index-DGZZhei7.js:43
Qk @ index-DGZZhei7.js:43
Fk @ index-DGZZhei7.js:43
jg @ index-DGZZhei7.js:41
(anonymous) @ index-DGZZhei7.js:43Understand this errorAI
index-DGZZhei7.js:793 Error fetching count data: NoSuchKey: The specified key does not exist.
...

aws-exports.js

No response

Manual configuration

Storage: {
S3: {
bucket: import.meta.env.VITE_S3_BUCKET,
region: import.meta.env.VITE_REGION
}
}

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending a response from the Amplify team. labels Feb 20, 2025
@GrahamEvans31
Copy link
Author

I just made all files in S3 public access, when I attempt to generate the URL or download with amplify, ONLY in production, it still returns this 404 /public/undefined for ANY string path I pass in.

@HuiSF HuiSF added investigating This issue is being investigated Storage Related to Storage components/category labels Feb 20, 2025
@jjarvisp
Copy link
Member

Hey @GrahamEvans31, thanks for opening this issue. Could you provide a full code example of the site where you are calling the downloadData API? Also, if you are able can you provide a network logs showing the generated path in the request URL?

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Feb 20, 2025
@jjarvisp jjarvisp added question General question and removed pending-triage Issue is pending triage labels Feb 20, 2025
@GrahamEvans31
Copy link
Author

Here's a console screenshot, this is ONLY in production. Every other stage works and just to be clear in dev I can easily read from the production bucket. This error of creating the signed URL only happens in production, it always outputs the "public/undefined" regardless of the input path.

Image Image

@GrahamEvans31
Copy link
Author

GrahamEvans31 commented Feb 20, 2025

const downloadResult = await downloadData({
          path: `public/metrics/${organizationId}/${year}/${("0" + month).slice(-2)}/CC.json`
        }).result;
const text = await downloadResult.body.text();
const data = JSON.parse(text);

@github-actions github-actions bot added the pending-maintainer-response Issue is pending a response from the Amplify team. label Feb 20, 2025
@jjarvisp
Copy link
Member

Thanks for the quick reply @GrahamEvans31. Can you also provide a code example for the call site of the list API?

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Feb 20, 2025
@GrahamEvans31
Copy link
Author

ListBucket is not related, I can add ListBucket to the bucket and then it just 404's on the key that is produced inside the downloadData function. 'public/undefined' see top error line, also as explained this code generates correct signed URLs in all other environments. But when executing from Netlify production environment (dev works correctly, even dev->prod bucket) it always logs this error and has a bad key 'public/undefined'

@github-actions github-actions bot added the pending-maintainer-response Issue is pending a response from the Amplify team. label Feb 20, 2025
@jjarvisp
Copy link
Member

@GrahamEvans31, can you try assigning the path parameter to a variable and logging the output in your production environment to see what the output is?

For example:

const path = `public/metrics/${organizationId}/${year}/${("0" + month).slice(-2)}/CC.json`;

// log out path parameter
console.log(path);

const downloadResult = await downloadData({
          path
        }).result;
const text = await downloadResult.body.text();
const data = JSON.parse(text);

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigating This issue is being investigated question General question Storage Related to Storage components/category
Projects
None yet
Development

No branches or pull requests

3 participants