Dealing with s3 using Python – Boto3 Module – Upload/Download files from bucket

We all know Amazon AWS, one of the AWS Features called s3, refer to Simple Storage Service which is is a service offered by Amazon Web Services that provides object storage through a web service interface.

Amazon Provide different ways to deal with s3, either by console or by AWSCLI, But In this post i choose to work with s3 in different way, as most of you know, i love python because it’s very simple, not complicated and cross-platform programming language.

You can deal and manage s3 using python by module called boto3, in previous version it was called boto (without 3), you have to install this module to allow python import the library, very simple step

pip3 install boto3

or by the project Interpreter that you are using, in my case i am using PyCharm Community, Nice to deal with, you can install any module by doing the following

File --> Setting --> Project interpreter --> Press on + sign --> and search for the module you want to install 

I uploaded the scripts to my Github like usual here, the repository includes two different file

  • Upload to S3
  • Download from s3

It’s very simple scripts, but you have to update the following to ensure access to AWS S3

Inside the upload file S3

  • ACCESS_KEY_ID
  • ACCESS_SECRET_KEY
  • BUCKET_NAME
  • The Location of the files

Inside the download from S3 file

  • ACCESS_KEY_ID
  • ACCESS_SECRET_KEY
  • BUCKET_NAME

Cheers ✌😉

Osama

Coding with Python

Python is a powerful high-level, object-oriented programming language created by Guido van Rossum.

It has simple easy-to-use syntax, making it the perfect language for someone trying to learn computer programming for the first time.

I Will keep working frequtely on this part and this programing langyage since i am using it on daily basis for different things such as Analytics, Scripting and Devops, for simple, easy to learn and more than this powerful.

For the begginers and people who wants simple code and examples i uploaded code samples on my github Press on the icon below.

icons8-github-50

 

Thank you

Osama

privileges Scripts

These script made by René Nyffenegger and shared here for knowledge

List user role and privileges :

select
lpad(' ', 2*level) || granted_role "User, his roles and privileges"
from
(
/* THE USERS */
select
null grantee,
username granted_role
from
dba_users
where
username like upper('%&enter_username%')
/* THE ROLES TO ROLES RELATIONS */
union
select
grantee,
granted_role
from
dba_role_privs
/* THE ROLES TO PRIVILEGE RELATIONS */
union
select
grantee,
privilege
from
dba_sys_privs
)
start with grantee is null
connect by grantee = prior granted_role;

Check System privileges:

select
lpad(' ', 2*level) || c "Privilege, Roles and Users"
from
(
/* THE PRIVILEGES */
select
null p,
name c
from
system_privilege_map
where
name like upper('%&enter_privliege%')
/* THE ROLES TO ROLES RELATIONS */
union
select
granted_role p,
grantee c
from
dba_role_privs
/* THE ROLES TO PRIVILEGE RELATIONS */
union
select
privilege p,
grantee c
from
dba_sys_privs
)
start with p is null
connect by p = prior c;

Object Privileges :

select
case when level = 1 then own || '.' || obj || ' (' || typ || ')' else
lpad (' ', 2*(level-1)) || obj || nvl2 (typ, ' (' || typ || ')', null)
end
from
(
/* THE OBJECTS */
select
null p1,
null p2,
object_name obj,
owner own,
object_type typ
from
dba_objects
where
owner not in
('SYS', 'SYSTEM', 'WMSYS', 'SYSMAN','MDSYS','ORDSYS','XDB', 'WKSYS', 'EXFSYS',
'OLAPSYS', 'DBSNMP', 'DMSYS','CTXSYS','WK_TEST', 'ORDPLUGINS', 'OUTLN')
and object_type not in ('SYNONYM', 'INDEX')
/* THE OBJECT TO PRIVILEGE RELATIONS */
union
select
table_name p1,
owner p2,
grantee,
grantee,
privilege
from
dba_tab_privs
/* THE ROLES TO ROLES/USERS RELATIONS */
union
select
granted_role p1,
granted_role p2,
grantee,
grantee,
null
from
dba_role_privs
)
start with p1 is null and p2 is null
connect by p1 = prior obj and p2 = prior own;
 
 Thank you 
Osama Mustafa 

DBA Scripts / Part No.4

This Is new Scripts for Database Administrator , But this Scripts to Check Performance and helping you in Tuning :

1-Script_1 . (Active Session/Execution Plan/Oracle 9i)
2-Script_2 (Active Session/Execution Plan / Any Version).
3-Script_3 (Plan History).
4-Script_4 (Number Of sesion).

Done & Enjoy

Osama Mustafa

Script to Extract Code to Recreate Materialized

This function will extract the DDL for an existing materialized view

SET serveroutput on
SET feedback off
UNDEF v_sql

DECLARE
v_task_name VARCHAR2 (100);
v_mview_owner VARCHAR2 (30) := UPPER ('&&ENTER_MVIEW_OWNER');
v_mview_name VARCHAR2 (30) := UPPER ('&&ENTER_MVIEW_NAME');
v_mview_sql VARCHAR2 (4000);
v_mview_log_sql VARCHAR2 (4000);
BEGIN
-- get mview text from data dictionary
SELECT DBMS_METADATA.get_ddl ('MATERIALIZED_VIEW', mview_name, owner)
INTO v_mview_sql
FROM dba_mviews
WHERE owner = v_mview_owner AND mview_name = v_mview_name;

SELECT DBMS_METADATA.get_dependent_ddl ('MATERIALIZED_VIEW_LOG',
referenced_name,
referenced_owner
)
INTO v_mview_log_sql
FROM dba_dependencies
WHERE referenced_type = 'TABLE'
AND referenced_name != v_mview_name
AND owner = v_mview_owner
AND NAME = v_mview_name;

DBMS_OUTPUT.put_line ('MVIEW SQL Is: ' || v_mview_sql);
DBMS_OUTPUT.put_line ('MVIEW LOG SQL Is: ' || v_mview_log_sql);
EXCEPTION
WHEN OTHERS
THEN
NULL;
END;
/