Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

Unable to upload file in AWS Lambda ? #174

Open
Ajinkz opened this issue Oct 29, 2021 · 3 comments
Open

Unable to upload file in AWS Lambda ? #174

Ajinkz opened this issue Oct 29, 2021 · 3 comments

Comments

@Ajinkz
Copy link

Ajinkz commented Oct 29, 2021

No description provided.

@jasonrollins
Copy link
Owner

I don't have any experience with that. I would assume that there are no issues as long as you can log into you SharePoint account from the Lambda server.

@Ajinkz
Copy link
Author

Ajinkz commented Nov 2, 2021

I was able to execute the following lines of code on a local machine but failed to run AWS lambda

from shareplum import Site
from shareplum import Office365
from shareplum.site import Version
import shareplum
print(shareplum.__version__)

username = config['sp_user'] # user mail id
password = config['sp_password']
basepath = config['sp_base_path'] # 'https://xxxxxxx.sharepoint.com/'
sitename = config['sp_site_name'] # 'https://xxxxxxx.sharepoint.com/sites/xxxxxx'
dirname = 'testdir' # directory where file is suppose to upload

authcookie = Office365(basepath, username=username, password=password).GetCookies()
site = Site(sitename,version=Version.v365, authcookie=authcookie)
    
spfolder = site.Folder('Shared Documents/'+ dirname)
        
allfiles = spfolder.files
for file in allfiles:
    print(file['Name'])
 
filename = '/tmp/'+ 'test-'+str(dateobj.date())+".csv"           
#
with open(filename,'rb') as file_input:
        print("Filename:",filename)
        try:
            #fileContent = file_input.read()
            spfolder.upload_file(file_input, filename)
            print("file uploaded")
        except Exception as err: 
            print("\nERROR occurred: \n" + str(err))

Error

Shareplum HTTP Post Failed : 400 Client Error: Bad Request for url: https://xxxxxxxx.sharepoint.com/sites/sharedlib/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents/testdir')/Files/add(url='/tmp/test-2021-11-10.csv',overwrite=true)

I'm able to get the list of files from the SharePoint location but I'm unable to upload the file using AWS Lambda.
Same code tested locally which runs fine but failed to work on Lambda

I'm using the following version of Layer in Lambda.
shareplum-9263cd6b-1270-42a8-9b2f-a647a9f25a47.zip

@Ajinkz Ajinkz changed the title How to use shareplum in AWS Lambda ? Unable to upload file in AWS Lambda ? Nov 10, 2021
@iampatterson
Copy link

I am currently fighting problems with using this code on Azure Functions. I found some problems with including the correct dependencies. It is important to double-check, as the requirements for the most current version can be found below.

Just an idea.

Regards

certifi==2019.11.28
cffi==1.14.0
chardet==3.0.4
cryptography==3.3.2
idna==2.9
lxml==4.6.5
ntlm-auth==1.4.0
pycparser==2.20
requests==2.23.0
requests-ntlm==1.1.0
requests-toolbelt==0.9.1
SharePlum==0.4.2
six==1.14.0
urllib3==1.26.5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants