Code Monkey home page Code Monkey logo

aws-alibaba's Introduction

AWS-Alibaba

Copying data from AWS S3 to Alibaba OSS using function compute service

import oss2
import boto3

def handler(event, context):

	S3_BUCKET_NAME      = 'AWS_SOURCE_BUCKET_NAME'
	AWS_KEY				= 'AWS_ACCOUNT_KEY'
	AWS_SECRET			= 'AWS_ACCOUNT_SECRET'

	OSS_KEY         	= 'ALIBABA_OSS_KEY'
	OSS_SECRET      	= 'ALIBABA_OSS_SECRET'
	OSS_BUCKET_NAME     = 'ALIBABA_DESTINATION_BUCKET_NAME'
	OSS_ENDPOINT    	= 'oss END POINT'  # For ex: 'oss-cn-beijing.aliyuncs.com'
	FILE_NAME          	= 'FILE_NAME_TO_BE_COPIED'

	# Create s3 bucket connection
	
	s3 = boto3.resource( 's3', aws_access_key_id=AWS_KEY, aws_secret_access_key=AWS_ACCOUNT_SECRET )
	s3_bucket = s3.Bucket( S3_BUCKET_NAME ) 

	# connect to oss
	oss_auth = oss2.Auth( OSS_KEY, OSS_SECRET )
	oss_bucket = oss2.Bucket( oss_auth, OSS_ENDPOINT, OSS_BUCKET_NAME )

	tmp_file = '/tmp/%s' % S3_BUCKET_NAME
	
	s3_bucket.download_file( FILE_NAME, tmp_file )

	with open(oss2.to_unicode(tmp_file), 'rb') as f:
		oss_bucket.put_object(FILE_NAME, f)
	print 'Key uploaded to oss.'

aws-alibaba's People

Contributors

gbhise avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.