How to copy from S3 to Windows shared drive/folder

I need to copy a small CSV file from my S3 bucket to on-prem Windows Shared Drive which is connected through VPN.

Can it be done using Lambda? Or should I try another aproach?

Origin: S3 bucket
Transporter: serverless
Destination: Windows Shared Folder/Drive

Thanks for your help.

Hi,
If anyone need, I was able to copy from Lambda to Shared Folder using a python library “PySMB”

I used code from here to test list dir: https://gist.github.com/joselitosn/e74dbc2812c6479d3678

Also, these docs: https://pysmb.readthedocs.io/en/latest/api/smb_SMBConnection.html

To copy, I used storeFile method.

Here the code I’ve used:
Obs.: It is need to upload to Lambda folder pysmb and pyasn1 librarys

import json
import boto3

from smb.SMBConnection import SMBConnection

def lambda_handler(event, context):
    
    conn = SMBConnection(userID, password, client_machine_name, server_name, domain=domain_name, use_ntlm_v2=True,
                     is_direct_tcp=True)
    
    conected = conn.connect(server_ip, 445)
    print('contected?')
    print(conected)
    

    files = conn.listPath('operacoes_varejo$', 'Carga Consignado', search=65591, pattern='*', timeout=30)
   
    #print files
    for file in files:
        print(file.filename)
    
    #Copy from s3  
    s3 = boto3.client('s3')
    objects3tmp = s3.download_file('bucketname', 'keyname', '/tmp/file')
    print('Downloaded..')
    
    #open rb (read binary)
    file_obj = open('/tmp/file', 'rb')
    
    #upload files to shared drive
    conn.storeFile('first_level_shared_folder', 'second_level/filename', file_obj)    
  
    
    conn.close()

    
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }
1 Like

how do we copy files from shared folder to S3 ? other way round ?

I was able to run code till : #print files
for file in files:
print(file.filename)