I`m trying to generate 2 consequence pressing post urls for posting to S3 using boto3. This urls I return to user to post 2 semantically connected files that have different format.
full_ecs_xsd_key = 'txn/jackalope/edispec/TPD/local/opikovets/my_test_file_3'
fields = {
"x-amz-meta-identity-id": user_id,
"x-amz-server-side-encryption": "AES256"
}
conditions = [
{"x-amz-meta-identity-id": user_id},
{"x-amz-server-side-encryption": "AES256"}
]
xsd_key = full_ecs_xsd_key + '.xsd'
pre_signed_xsd_post_url = copy.deepcopy(s3_client.generate_presigned_post(
bucket_name, xsd_key,
Fields=fields,
Conditions=conditions
))
ecs_key = full_ecs_xsd_key + '.ecs'
pre_signed_ecs_post_url = copy.deepcopy(s3_client.generate_presigned_post(
bucket_name, ecs_key,
Fields=fields,
Conditions=conditions
))
as a result, I get 2 urls which seems to be working, but I`m not able to post data to the second url (pre_signed_ecs_post_url). Getting an error
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>AccessDenied</Code>
<Message>Invalid according to Policy: Policy Condition failed: ["eq", "$key", "txn/jackalope/edispec/TPD/local/opikovets/my_test_file_3.xsd"]</Message>
<RequestId>1343F7E406E82C1A</RequestId>
<HostId>wm0U14OouoMkbm0bWIqkYDtP7fgR2A+0Q/Mvhvo9sJ7paaXDiMWfqnjCMR4mc5euPcXCyP3u2/w=</HostId>
</Error>
What is confusing here is that key, displayed in the error is actually a key for the first url, not the second one. So, I think that when I call generate_presigned_post for the first time it creates an instance of a class that is also used for creating second url...
But that`s only a guess, and I have no idea how to solve this particular problem
Per @Michael-sqlbot comments, fields and conditions are changing during the generate_presigned_post() execution, so I`ve changed the call to:
ecs_key = full_ecs_xsd_key + '.ecs'
pre_signed_ecs_post_url = s3_client.generate_presigned_post(
bucket_name, ecs_key,
Fields=copy.deepcopy(fields),
Conditions=copy.deepcopy(conditions)
)
xsd_key = full_ecs_xsd_key + '.xsd'
pre_signed_xsd_post_url = s3_client.generate_presigned_post(
bucket_name, xsd_key,
Fields=copy.deepcopy(fields),
Conditions=copy.deepcopy(conditions)
)
and everything worked just fine