Module - 2 Storage Assignment
Module - 2 Storage Assignment
1.Upload
Dropdown: For selecting a bucket in S3 storage.
Table: For listing all the objects inside the selected bucket in dropdown.
Text Input: For getting a path for the file that is to be uploaded.
File picker: For uploading the file.
Button: This will be used to fire the upload query.
Queries
We'll create the following queries:
1. getBuckets
2. listObjects
3. uploadToS3
4. download
getBuckets
This query will fetch the list of all the buckets in your S3. Just create a new query, select AWS
S3 data source, and choose List buckets operation. Name the query getBuckets and
click Save.
2.Download
Create a new query and select Signed URL for download operation. In the Bucket field,
enter {{components.dropdown1.value}} and in Key
enter {{components.table1.selectedRow.Key}}.
Edit the properties of the table, add a Event handler for running the download query
for Row clicked event. This will generate a signed url for download every time a row is
clicked on the table.
uploadToS3
Create a new query, select the Upload object operation. Enter the following values in their
respective fields:
Bucket: {{components.dropdown1.value}}
Key: {{ components.textinput1.value + '/' +components.filepicker1.file[0].name}}
Content type: {{components.filepicker1.file[0].type}}
Upload data: {{components.filepicker1.file[0].base64Data}}
Encoding: base64
Configure the File Picker:
Click on the widget handle to edit the file picker properties:
Change the Accept file types to {{"application/pdf"}} for the picker to accept only pdf
files or {{"image/*"}} for the picker to accept only image files . In the screenshot
below, we have set the accepted file type property to {{"application/pdf"}} so it will
allow to select only pdf files:
Change the Max file count to {{1}} as we are only going to upload 1 file at a time.
Select a pdf file and hold it in the file picker.
Final steps, go to the Advanced tab of the uploadToS3 query and add a query to
run listObjects query so that whenever a file is uploaded the tabled is refreshed.
3.Copy your object to a folder
Create a User Policy
To be able to perform S3 bucket operations we need to give the copy_user some
permissions.
To do so go to the Destination AWS account under the IAM service, then select users and
then select the user that will be used to do the copy/move operations. On the user page
select the Attach User Policy button (see above - Image 1.)
User Policy
In this User Policy we give the user the follow permissions:
ListAllMyBuckets - the ability to list all available S3 buckets
GetObject - the ability the get an S3 object
ListBucket - the ability to list all the objects for the given bucket (in this case the to-
destination bucket)
GetBucketLocation - the ability to get the location of the bucket which is needed
before any operations can be performed on a bucket.
We finally gave the user policy the name bucket_copy_move_policy,
Create a Bucket Policy
At this point the user has the right to perform some S3 operations but do not really have
permission to access the objects within the from-source bucket yet. The reason is because
the from-source bucket do not belong to the Destination AWS account but to
the Source AWS Account. So we need to allow the user to get an object in the from-
source bucket, by giving him permission via the from-source bucket policy, beloning to
the Source AWS Account.
To do this we make use of a Bucket Policy. Look at how to add a bucket policy.
Amazon have some good documentation explaining How Amazon S3 Authorizes a Request
for a Bucket Operation and how the permission validation works during a typical S3 object
request, but for now lets get practical. If you just want to copy/move objects then past the
bucket policy below into your bucket's policy.
Bucket Policy
To do this you need to log into the Source AWS account, then go to the S3 service. Inside the
S3 console select the from-source bucket and click on the Properties button and then select
the Permissions section
Click on the Add bucket policy button and past the bucket policy given above. After pasting
the bucket policy click on the Save button as shown in image 3 below.
3.When the confirmation dialog box appears, review the details, enter Yes, and select OK.
4.Wait for the delete operation to begin.
After a few minutes:
o A yellow status banner appears on the bucket details page. The progress bar
represents what percentage of objects have been deleted.
o (read-only) appears after the bucket's name on the bucket details page.
o (Deleting objects: read-only) appears next to the bucket's name on the
Buckets page.
5.As required while the operation is running, select Stop deleting objects to halt the process.
Then, optionally, select Delete objects in bucket to resume the process.
When you select Stop deleting objects, the bucket is returned to write mode; however, you
can't access or restore any objects that have been deleted.
6.Wait for the operation to complete.
When the bucket is empty, the status banner is updated, but the bucket remains read only.
7.Do one of the following:
Exit the page to keep the bucket in read-only mode. For example, you might keep an
empty bucket in read-only mode to reserve the bucket name for future use.
Delete the bucket. You can select Delete bucket to delete a single bucket or return
the Buckets page and select Actions > Delete buckets to remove more than one
bucket.
Return the bucket to write mode and optionally reuse it for new objects. You can
select Stop deleting objects for a single bucket or return to the Buckets page and
select Action > Stop deleting objects for more than one bucket.