Delete an object from S3.
Deletes the specified object from S3 using an HTTP DELETE request. This operation requires AWS credentials to be configured.
@param[in] key The S3 object key to delete @return .true. if deletion succeeded, .false. on error
Note
Requires AWS credentials (access_key and secret_key) to be set in configuration.
Warning
This operation is irreversible. Deleted objects cannot be recovered.
Warning
Returns .false. if credentials are missing or deletion fails.
logical :: success
success = s3_delete_object('temp/scratch_data.txt')
if (success) then
print *, 'Object deleted successfully'
else
print *, 'Deletion failed'
end if
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | key |
function s3_delete_object(key) result(success) character(len=*), intent(in) :: key logical :: success character(len=2048) :: url character(len=4096) :: cmd integer :: ios success = .false. if (.not. initialized) return ! For public buckets without auth, DELETE won't work if (len_trim(current_config%access_key) == 0) then print *, 'Warning: DELETE requires AWS credentials' return end if ! Build URL if (current_config%use_https) then write(url, '(A,A,A,A,A,A)') 'https://', & trim(current_config%bucket), '.', & trim(current_config%endpoint), '/', & trim(key) else write(url, '(A,A,A,A,A,A)') 'http://', & trim(current_config%bucket), '.', & trim(current_config%endpoint), '/', & trim(key) end if ! Build curl command for DELETE write(cmd, '(A,A,A)') 'curl -s -X DELETE "', trim(url), '"' call execute_command_line(cmd, exitstat=ios) success = (ios == 0) end function s3_delete_object