Uploads given file to S3 :param file_name: Path to the file that will be uploaded :param remote_path: be uploaded :return: VersionId of the latest upload
(self, file_name, remote_path)
| 92 | self._artifact_metadata = None |
| 93 | |
| 94 | def upload(self, file_name, remote_path): |
| 95 | """ |
| 96 | Uploads given file to S3 |
| 97 | :param file_name: Path to the file that will be uploaded |
| 98 | :param remote_path: be uploaded |
| 99 | :return: VersionId of the latest upload |
| 100 | """ |
| 101 | |
| 102 | if self.prefix and len(self.prefix) > 0: |
| 103 | remote_path = f"{self.prefix}/{remote_path}" |
| 104 | |
| 105 | # Check if a file with same data exists |
| 106 | if not self.force_upload and self.file_exists(remote_path): |
| 107 | LOG.debug( |
| 108 | f"File with same data already exists at {remote_path}. " |
| 109 | "Skipping upload" |
| 110 | ) |
| 111 | return self.make_url(remote_path) |
| 112 | |
| 113 | try: |
| 114 | # Default to regular server-side encryption unless customer has |
| 115 | # specified their own KMS keys |
| 116 | additional_args = {"ServerSideEncryption": "AES256"} |
| 117 | |
| 118 | if self.kms_key_id: |
| 119 | additional_args["ServerSideEncryption"] = "aws:kms" |
| 120 | additional_args["SSEKMSKeyId"] = self.kms_key_id |
| 121 | |
| 122 | if self.artifact_metadata: |
| 123 | additional_args["Metadata"] = self.artifact_metadata |
| 124 | |
| 125 | print_progress_callback = ProgressPercentage( |
| 126 | file_name, remote_path |
| 127 | ) |
| 128 | future = self.transfer_manager.upload( |
| 129 | file_name, |
| 130 | self.bucket_name, |
| 131 | remote_path, |
| 132 | additional_args, |
| 133 | [print_progress_callback], |
| 134 | ) |
| 135 | future.result() |
| 136 | |
| 137 | return self.make_url(remote_path) |
| 138 | |
| 139 | except botocore.exceptions.ClientError as ex: |
| 140 | error_code = ex.response["Error"]["Code"] |
| 141 | if error_code == "NoSuchBucket": |
| 142 | raise NoSuchBucketError(bucket_name=self.bucket_name) |
| 143 | raise ex |
| 144 | |
| 145 | def upload_with_dedup(self, file_name, extension=None): |
| 146 | """ |