AWS Classroom Series – 07/Sept/2020

CLI FOR S3 buckets

  • Create an S3 bucket from CLI

  • Copy some folder of your system with files and directories to s3

  • Copy s3 bucket or sync s3 bucket contents to your system

  • Execute the following commands

aws s3 help
aws s3 mb help
aws s3 cp help
aws s3 sync help
  • Create a shell script for which takes two arguments
    1. s3 bucket name
    2. folder to be synced
#!/bin/bash

# Usage synctos3.sh <bucketname>  <foldertobesynced>

if [[ ! $# == 2 ]]
then
	echo "invalid arguments. Usage is synctos3.sh <bucketname>  <foldertobesynced>"
	exit 1
fi

bucket_name="s3://$1"
foldertobesynced="$2"

if [[ ! -d $foldertobesynced ]] 
then
	echo "invalid directory"
	exit 1
fi

aws s3 sync "$foldertobesynced" "$bucket_name" && echo "Sync completed" || echo "Sync failed"
  • Create a Powershell script to do the same
$s3_bucket_name = Read-Host "Enter you S3 Bucket Name (in the form of s3 uri)"
$folder_to_be_synced = Read-Host "Enter the folder to be synced"
aws s3 sync $folder_to_be_synced $s3_bucket_name

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin