'unable to set metaData or tags on S3 Object

Trying to put Tags or metaData on existing or new object in bucket. I succeed with AWS CLI, however it has no effect with AWS JS SDK 3 I Getting back http 200 ok result

resultTag {$metadata: {…}, VersionId: undefined} $metadata: attempts: 1 cfId: undefined extendedRequestId: undefined httpStatusCode: 200 requestId: undefined totalRetryDelay: 0 [[Prototype]]: Object VersionId: undefined

However no tags, nor metadata present, on S3 Object Doubled checked the IAM policy attached to Cognito Pool : I allowed everything (S3: * ) to troubleshoot, see snippet

CORS config allow all headers * to allow for x-amz-headers to pass through.

// IAM Policy
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "s3:*"
                ],
                "Resource": [
                    "arn:aws:s3:::MY_BUCKET",
                    "arn:aws:s3:::MY_BUCKET/*",
                ]
            }
        ]
    }
    
    const s3Client = new S3Client({
      region: REGION,
      credentials: fromCognitoIdentityPool({
        client: new CognitoIdentityClient({ region: REGION }),
        identityPoolId: params.COGNITO_ID_POOL, 
      }),
    });

    // attempt 1 with PutObjectCommand

    const taggingResult = await s3Client.send(new PutObjectTaggingCommand
      ({
        Bucket,
        Key,
        Tagging: { TagSet: [ { Key: "key1", Value: "value1"} ] }
      })
    );

    // metadata issue, upload succeeds however metadata is missing
    const parallelUploads3 = new Upload({
        client: s3Client,
        params: { Bucket, Key, Body, Metadata:  {
            path: '/a/b/c',
            uri
          }
        },
        queueSize: 4, // optional concurrency configuration
        partSize: 1024 * 1024 * 5, // optional size of each part, in bytes, at least 5MB
        leavePartsOnError: false, // optional manually handle dropped parts
    });
      
      await parallelUploads3.done(); // upload succeeds however metadata not on S3 object ...


    // yet another attempt : try to add tags through middleware => no effect on S3 object's metadata :-(
    // obviously this code should be before s3Cient.send 
    s3Client.middlewareStack.add(
            (next, context) => async (args) => {
              args.request.headers["x-amz-meta-foo"] = "bar";
              const result = await next(args);

              return result;
            },
            {
              step: "build",
              name: "addFooMetadataMiddleware",
              tags: ["METADATA", "FOO"],
            }
          );

Any suggestions ? Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source