Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

[Enhancement] Modify the write location to /tmp/ directory so that fuelsdk can be utilized in aws lambda #128

Open
cheneyshreve opened this issue Jan 12, 2021 · 3 comments

Comments

@cheneyshreve
Copy link

Is your feature request related to a problem? Please describe
A clear and concise description of what the problem is.
I deployed a lambda function that uses fuelsdk-python to authenticate with salesforce marketing cloud api, retrieve data from a data extension, and peform pagination. This works brilliantly when running locally using pure python. When I deploy the logic within an aws python function, using the serverless framework, I get the error below when I execute the function. As a side note, I could never get this to work locally using environment variables, but it always works when I use phyton.config so I deploy to a private aws bucket that does not permit public access. The lamba function itself, however, does have adequate permissions to read/write to the relevant s3 buckets. I believe the error below is down to the fact that aws lambda will only let you write to '/tmp/' directory, so it might be just a very quick code update to do this.

  "errorMessage": "[Errno 30] Read-only file system: '/var/task/FuelSDK/ExactTargetWSDL.xml'",
  "errorType": "OSError",
  "stackTrace": [
    "  File \"/var/task/handler.py\", line 112, in paginate\n    myClient = ET_Client.ET_Client()\n",
    "  File \"/var/task/FuelSDK/client.py\", line 56, in __init__\n    self.configure_client(get_server_wsdl, params, tokenResponse)\n",
    "  File \"/var/task/FuelSDK/client.py\", line 130, in configure_client\n    self.wsdl_file_url = self.load_wsdl(wsdl_server_url, wsdl_file_local_location, get_server_wsdl)\n",
    "  File \"/var/task/FuelSDK/client.py\", line 224, in load_wsdl\n    self.retrieve_server_wsdl(wsdl_url, file_location)\n",
    "  File \"/var/task/FuelSDK/client.py\", line 241, in retrieve_server_wsdl\n    f = open(file_location, 'w')\n"
  ]
}

I think the resolution, for aws lambda, would just be to modify line 241 of client.py

f = open(file_location, 'w')

modification would likely need to be this, because this is similar to how you write to s3 buckets via lambda:
f = open('/tmp/'+ file_location, 'w')

I'm uncertain, if I were to clone this repo and make the modification locally for reference, how I would
then reference that via the traditional requirements route (e.g. using pip and requirements.txt that are
utilized by aws lambda).

Describe the solution you'd like
A clear and concise description of what you want to happen.
to be able to use fuelsdk-python within aws lambda function

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
deploying with amplify or another route on aws. lambda has much greater cost benefits.

Additional context
Add any other context or screenshots about the feature request here.
I'd be happy to contribute if someone can point me in the right direction. The fuelsdk is really valuable to the work that I'm doing and it would be amazing to be able to use it with aws lambda.

@vijayprakashpj
Copy link

The WSDL file will be downloaded to the location of your choice if you set wsdl_file_local_loc in params and get_server_wsdl in the constructor argument.

Refer this: https://github.com/salesforce-marketingcloud/FuelSDK-Python/blob/master/FuelSDK/client.py#L223

Example:

stubObj = ET_Client.ET_Client(
  True, False,
  {
      'clientid': '<CLIENT_ID>',
      'clientsecret': '<CLIENT_SECRET>',
      'defaultwsdl': 'https://webservice.exacttarget.com/etframework.wsdl',
      'authenticationurl': '<AUTH TENANT SPECIFIC ENDPOINT>',
      'baseapiurl': '<REST TENANT SPECIFIC ENDPOINT>',
      'soapendpoint': '<SOAP TENANT SPECIFIC ENDPOINT>',
      'wsdl_file_local_loc': r'/tmp/ExactTargetWSDL.xml',
      'useOAuth2Authentication': 'True',
      'accountId': '<TARGET_ACCOUNT_ID>',
      'scope': '<PERMISSION_LIST>'
      'applicationType': '<APPLICATION_TYPE>'
      'redirectURI': '<REDIRECT_URI_FOR_PUBLIC/WEB_APP>'
      'authorizationCode': '<AUTHORIZATION_CODE_FOR_PUBLIC/WEB_APP>'
  })

@cheneyshreve
Copy link
Author

cheneyshreve commented Jan 12, 2021 via email

@ulinares
Copy link

Hi, an unrelated comment to the issue, @cheneyshreve how do you perform pagination on the data extension?
Thanks.

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

No branches or pull requests

3 participants