AWS S3-Snowflake Pipeline Example | Snowflake Tutorials In Hindi

Image could not load

Image on unsplash

let suppose आपके AWS account में snowflake नाम की एक bucket है। जिसके अंदर employee.csv नाम की file है , इस file में कुछ fields और data होगा ।

AWS Setup IAM Role

अब हालाँकि हम snowflake से s3 bucket से data access करेंगे तो हम इसके proper access के लिए एक IAM role create कर लेंगे।

IAM role setup करने के लिए नीचे दिए गए steps को follow करे -

  • Services में जाकर IAM search करें , फिर roles पर click करें। यहाँ कुछ predefined roles होंगे।

  • then , Create role button पर click करें > फिर AWS account को select करें और उसके नीचे दिए गए options में से This account select करके Require external ID को भी select करें । मतलब इस role को कोई third party assume करके use करेगी ।

  • फ़िलहाल Require external ID के लिए 0000 enter करके Next पर click करें।

  • इसके बाद आपको permissions Add करनी हैं , जिसमे से आप s3FullAccess select कर लें , या need के according permissions set कर दें अपनी bucket के लिए।

  • finally permissions set करने के बाद role name दे फिर save कर दे।

Setup Table In Snowflake

अब अपने snowflake account में login करके एक particular warehouse में एक database > schema > table बना ले।

हम ऐसा माँ कर चलते हैं , कि आपके bucket में uploaded employee.csv में 5 fields हैं जिनके लिए table structure कुछ ऐसा होगा।

create or replace table employee ( ID int, First_Name varchar(200), Last_Name varchar(200), Location varchar(200), Salary int );

Table structure और table का नाम कुछ भी हो सकता है , need के according आप इसे change कर सकते हैं।

Snowflake Integration

अब time है real process का , सबसे पहले हम integration create करेंगे -

create or replace storage integration AWS_S3_TEST type = external_stage storage_provider = 's3' enabled = true storage_aws_role_arn = 'arn:aws:iam::712277605078:role/snowflakeRoleName' -- your aws role arn storage_allowed_locations = ('s3://snowflake/'); -- your bucket name

Show all integration list

show integrations;

describe a particular integration

desc storage integration AWS_S3_TEST;

describe command आपको integration के बारे में जानकारी देगी जिसमे से STORAGE_AWS_IAM_USER_ARN और STORAGE_AWS_EXTERNAL_ID को copy करके , अपने aws IAM Role की trust policy में set कर दें।

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Effect": "Allow",
			"Action": "sts:AssumeRole",
			"Principal": {
				"AWS": "STORAGE_AWS_IAM_USER_ARN"
			},
			"Condition": {
				"StringEquals": {
					"sts:ExternalId": "STORAGE_AWS_EXTERNAL_ID"
				}
			}
		}
	]
}

Snowflake Stage

अब बारी है stage को set करने की , जिसमे सबसे पहले हम एक file format भी बनाएंगे।

-- create file format as per uploaded file create or replace file format csv_file_format type='CSV' field_delimiter=',' skip_header=1;

Create Stage

create or replace stage aws_s3_stage storage_integration=AWS_S3_TEST file_format=csv_file_format url='s3://snowflake/'; -- aws s3 bucket name

list all stages

list @aws_s3_stage;

यह command run करने पर आपके s3 bucket में मौजूद सभी files को list कर देगी ।

Authorization के according आप यही से किसी particular file को remove भी कर सकते हैं या read भी कर सकते हैं।

Import Data From AWS S3 Bucket

Finally अब हम uploaded csv file से table में data load कर सकते हैं।

copy into EMP from @aws_s3_stage file_format=(format_name=csv_file_format) on_error='Continue';

See all records

select * from employee;

Snowflake Make Pipeline

हालाँकि अभी s3 से data , database table में manually load हो रहा है। Pipeline का use करके हम इसे automate कर सकते हैं।

जैसे ही s3 bucket में data upload होगा तो Automatically load हो जायगा।

create or replace pipe s3_pipe auto_ingest = true as copy into employee from @aws_s3_stage file_format=(format_name=csv_file_format);

List all pipelines

show pipes;

यह command आपको सभी pipelines की list देगी , जिसमे एक notification channel होगा , इसे copy कर ले क्योंकि इसी का use करके हम automate करेंगे।

automate करने के लिए s3 bucket में एक notification / queue channel create करें और show pipes; command से generated notification channel add करके SQS create कर दे।

SQS Notification create करने के लिए s3 bucket > properties > create notification > choose SQS queue .

इतना setup कर लेने के बाद अगर आप फिर से same file upload करोगे तो file से data automatically snowflake table में ingest हो जायगा।

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook