AWS hints, tips and how-tos. Things that have been picked while building out our AWS environment.
Redshift - Show Tables in schema
Get link
Facebook
X
Pinterest
Email
Other Apps
select t.table_name
from information_schema.tables t
where t.table_schema = 'myschema'-- put your schema name here
and t.table_type = 'BASE TABLE'
orderby t.table_name;
Formatting datetime in Python can be a 'pain'. Formatting works in two directions - From a string to datetime. - From a datetime to string. The easiest way to remember how things work using the strptime and strftime is that: strptime (string)(parse)(time) strftime (string)(format)(time) Format a datetime to a string from datetime import datetime print(datetime.today( ).strftime('%Y-%m-%d %H:%M:%S')) 2020-07-22 10:07:16 Parse a String to datetime from datetime import datetime date_time = ' 2020-07-22 10:07:16 ' dt_object = datetime .strptime(date_time, ' %Y-%m-%d %H:%M:%S' )
Wait for … When writing shell scripts by using the CLI there will be the need to wait for a specific condition from time to time. For example, after initiating an EBS snapshot your script might need to wait until the snapshot was completed. Waiting can be achieved with a polling loop and a describe-* command. But there is a simpler solution built into the CLI for this: aws <service> wait <condition>. The following contains a wait command that will block the script until the snapshot has been completed. #!/bin/bash echo "Waiting for EBS snapshot" aws ec2 wait snapshot-completed --snapshot-ids snap-id_abc echo "EBS snapshot completed" You'll find many more uses for this, and hopefully no more corruption as commands compete.
S3 has no rename functionality. You need to copy to a new 'file' and delete the original. In python using boto3 s3 = boto3 . resource ( 's3' ) s3 . Object ( 'my_bucket' , 'my_file_new' ). copy_from ( CopySource = 'my_bucket/my_file_old' ) s3 . Object ( 'my_bucket' , 'my_file_old' ). delete ()
Comments
Post a Comment