AWS Rekognition报InvalidParameterException异常排查请求
Let’s walk through the most likely causes for this sudden error—since your code worked fine last month, the issue is probably a recent change to permissions, the image itself, or your configuration.
Possible Causes & Fixes
1. S3 Object/Bucket Permission Changes
Rekognition needs explicit permission to read the S3 object you’re passing in. Even if it worked before, permissions might have been modified recently:
- Check IAM Role Permissions: Ensure the IAM role your Node.js app uses has the
s3:GetObjectpermission for themastekinnoations3learningbucket (and specifically the1527119837382460.jpegobject). Double-check if any recent policy updates revoked this access. - Verify S3 Bucket Policy: Make sure the bucket policy doesn’t block Rekognition from accessing objects. You can test this quickly with the AWS CLI:
If the CLI throws the same error, the problem is likely permission-related, not your Node.js code.aws rekognition detect-faces --image '{"S3Object": {"Bucket": "mastekinnoations3learning", "Name": "1527119837382460.jpeg"}}' --region us-west-2
2. Corrupted or Invalid Image File
It’s possible the image in S3 was overwritten, corrupted, or no longer meets Rekognition’s requirements:
- Download and Validate the Image: Grab the image from S3 and confirm it opens properly in a viewer. Rekognition supports JPEG, PNG, and BMP files, with a maximum size of 15MB and minimum resolution of 8x8 pixels.
- Check for Accidental Overwrites: Verify no recent updates replaced the original image with a broken or unsupported file.
3. Hardcoded Parameter Mistakes
Looking at your code, you’re importing s3BucketName and s3BucketKeyName from constants but then hardcoding the bucket and object name in the params object. This could lead to mismatches if the constants were updated but the hardcoded values weren’t:
- Replace Hardcoded Values with Constants: Update your params to use the imported variables instead of static text:
Also double-check ifconst params = { Image: { S3Object: { Bucket: s3BucketName, Name: s3BucketKeyName } } };mastekinnoations3learninghas a typo (e.g., maybe it should bemasteinnovations3learning? The "noa" seems off).
4. AWS SDK or Region Mismatch
- Update AWS SDK: Older versions of the AWS SDK might have compatibility issues with the Rekognition API. Run
npm update aws-sdkto get the latest version and test again. - Confirm Region Configuration: Ensure your AWS config (in
config.json) is set tous-west-2(matching your S3 bucket’s region). Mismatched regions can sometimes trigger parameter errors even if the API call is technically valid.
Quick Test to Isolate the Issue
If you’re still stuck, try passing the image as a base64-encoded string instead of using S3 to rule out S3-specific problems. This will help confirm if the issue is with the image itself or the S3/Rekognition integration.
内容的提问来源于stack exchange,提问作者Sourabh Jain

