aws-beam/aws-elixir

no function clause matching in AWS.Request.build_params/2

Closed this issue · 2 comments

Hello! Thank you for this lib. I was looking to migrate over from ex_aws but had problems getting S3 working. It wasn't on 0.6.0 so I used the main branch and am getting this error:

** (FunctionClauseError) no function clause matching in AWS.Request.build_params/2
   (aws 0.6.0) lib/aws/request.ex:85: AWS.Request.build_params([{"ACL", "x-amz-acl"}, {"CacheControl", "Cache-Control"}, {"ContentDisposition", "Content-Disposition"}, {"ContentEncoding", "Content-Encoding"}, {"ContentLanguage", "Content-Language"}, {"ContentLength", "Content-Length"}, {"ContentMD5", "Content-MD5"}, {"ContentType", "Content-Type"}, {"Expires", "Expires"}, {"GrantFullControl", "x-amz-grant-full-control"}, {"GrantRead", "x-amz-grant-read"}, {"GrantReadACP", "x-amz-grant-read-acp"}, {"GrantWriteACP", "x-amz-grant-write-acp"}, {"ObjectLockLegalHoldStatus", "x-amz-object-lock-legal-hold"}, {"ObjectLockMode", "x-amz-object-lock-mode"}, {"ObjectLockRetainUntilDate", "x-amz-object-lock-retain-until-date"}, {"RequestPayer", "x-amz-request-payer"}, {"SSECustomerAlgorithm", "x-amz-server-side-encryption-customer-algorithm"}, {"SSECustomerKey", "x-amz-server-side-encryption-customer-key"}, {"SSECustomerKeyMD5", "x-amz-server-side-encryption-customer-key-MD5"}, {"SSEKMSEncryptionContext", "x-amz-server-side-encryption-context"}, {"SSEKMSKeyId", "x-amz-server-side-encryption-aws-kms-key-id"}, {"ServerSideEncryption", "x-amz-server-side-encryption"}, {"StorageClass", "x-amz-storage-class"}, {"Tagging", "x-amz-tagging"}, {"WebsiteRedirectLocation", "x-amz-website-redirect-location"}], <<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 1, 0, 75, 0, 75, 0, 0, 255, 219, 0, 67, 0, 16, 11, 12, 14, 12, 10, 16, 14, 13, 14, 18, 17, 16, 19, 24, 40, 26, 24, 22, 22, 24, 49, 35, 37, 29, ...>>)
    (aws 0.6.0) lib/aws/s3.ex:4515: AWS.S3.put_object/5

Let me know if you need anything else. Thank you!

I ran into this same issue. Strangely, I was able to get around it by wrapping the file data in a map, but then the uploaded file contains the whole map serialized rather than the original file. Similarly, when trying to download a file uploaded with other means using get_object it chokes because it tries to parse the file data as XML here: https://github.com/aws-beam/aws-elixir/blob/master/lib/aws/s3.ex#L5707

I'm happy to help work on these issues.

@lumenlunae This is fixed in master. Now you can pass the Body as a key of input when using AWS.S3.pub_object/5, like this:

client = AWS.Client.create("your-key", "your-secret", "us-east-1")
file =  File.read!("./tmp/your-file.txt")
md5 = :crypto.hash(:md5, file) |> Base.encode64()

AWS.S3.put_object(client, "your-bucket-name", "foo/your-file-on-s3.txt", %{"Body" => file, "ContentMD5" => md5})

The md5 is optional here, but it's easier to check if works because S3 will cause an error in case the file is corrupted. Also, the return of this operation is nil. You can use AWS.S3.list_objects_v2(client, bucket_name) to retrieve the list of files.

Thanks for open the issue! 💜
This will be available in a new version soon.

cc/ @tfwright