Posts tagged with aws-lambda

just wondering if someone can help me with this issue: I am trying to run a code in a lambda function and I have created a layer for this using a docker to create the needed libs:

# Use an official Amazon w/python3 FROM public.ecr.aws/lambda/python:3.9 # Create and activate a virtual environment RUN python3.9 -m venv /app/venv ENV PATH="/app/venv/bin:$PATH" # Install required packages COPY . . RUN pip3 install --upgrade pip RUN pip3 install --platform manylinux2014_x86_64 --target ./venv/lib/python3.9/site-packages --python-version 3.9 --only-binary=:all:  -r requirements.txt 
when i upload the function code and test it i am receiving this error: [ERROR] Runtime.ImportModuleError: Unable to import module 'google_conversion_lambda': google-ads Traceback (most recent call last):INIT_REPORT Init Duration: 3853.19 ms Phase: init Status: error   Error Type: Runtime.Unknown [ERROR] Runtime.ImportModuleError: Unable to import module 'google_conversion_lambda': google-ads Traceback (most recent call last):INIT_REPORT Init Duration: 25715.69 ms    Phase: invoke   Status: error   Error Type: Runtime.Unknown 

the import is coded like this:

from google.ads.googleads.client import GoogleAdsClient 

its is weird and I am running out of ideas to try. Any suggestions or other leads that I can try?

I already tried:

  1. On the code Zip file include all the google libraries needed along with the function.
  2. Rebuilding as a layer, with other building methods using the docker.

Both shows the same results.

EDIT: Just to let you know the issue here is that I was zipping the files on a windows environment and even the zipping process should happen inside the docker environment (Linux) after that we are good to export the zip file and update the layer.

This code is being used on aws lambda for making Google ads client

try:     googleads_client = GoogleAdsClient.load_from_dict(credentials, version="v11",) except GoogleAdsException as e:     print(f"Google Ads Exception: {e.message}") 

Unfortunately this is running into time out issue even if the time is set to 3 minutes. As there is no error, It is not possible to debug the issue. Any experienced developer can share some tips? Thanks alot

I am trying to setup a webhook in AWS Lambda (using API Gateway) for Meta's WhatsApp Business API. They have the following guidelines:

Whenever your endpoint receives a verification request, it must:

Verify that the hub.verify_token value matches the string you set in the Verify Token field when you configure Webhooks in your App Dashboard (you haven't set up this token string yet). Respond with the hub.challenge value."

I have setup all the query strings it needs in the API gateway. Here is what my lambda handler looks like:

def lambda_handler(event, context):     response = {         "status": 400,         "body" : "failed"     }          print(str(event))          print("Received context" + str(context))          if(len(event) != 0 and (event['hub.verify_token'] == "some value")):         response['status'] = 200         response['body'] = event['hub.challenge']         return event['hub.challenge']               #print(response)         #returnResponse = re.findall('[0-9]+', event['hub.challenge'])         #return returnResponse[0]              else:         return(response) 

the event looks like:

{     "hub.mode" : "some value",     "hub.verify_token": "some value",     "hub.challenge": "1158201444" } 

The response in AWS console looks like "1158201444" but on meta's end, the response looks like "\"1158201444\"" and the webhook confirmation fails in Meta's dashboard.

How can remove the extra characters and decode the string? I have already tried regex and still getting the extra characters (\"\").

Does Boto3 client support connectors for GoogleAds and FacebookAds? According to documentation we can use Custom Connector but when i try to use it in the code i get the below error saying it should be one of the built in types.

[ERROR] ParamValidationError: Parameter validation failed: Unknown parameter in connectorProfileConfig.connectorProfileProperties: "CustomConnector", must be one of: Amplitude, Datadog, Dynatrace, GoogleAnalytics, Honeycode, InforNexus, Marketo, Redshift, Salesforce, ServiceNow, Singular, Slack, Snowflake, Trendmicro, Veeva, Zendesk, SAPOData Unknown parameter in connectorProfileConfig.connectorProfileCredentials: "CustomConnector", must be one of: Amplitude, Datadog, Dynatrace, GoogleAnalytics, Honeycode, InforNexus, Marketo, Redshift, Salesforce, ServiceNow, Singular, Slack, Snowflake, Trendmicro, Veeva, Zendesk, SAPOData Traceback (most recent call last):   File "/var/task/lambda_function.py", line 34, in lambda_handler     response = client.create_connector_profile(   File "/var/runtime/botocore/client.py", line 391, in _api_call     return self._make_api_call(operation_name, kwargs)   File "/var/runtime/botocore/client.py", line 691, in _make_api_call     request_dict = self._convert_to_request_dict(   File "/var/runtime/botocore/client.py", line 739, in _convert_to_request_dict     request_dict = self._serializer.serialize_to_request(   File "/var/runtime/botocore/validate.py", line 360, in serialize_to_request     raise ParamValidationError(report=report.generate_report()) 

Code in Lambda :

import json import boto3 def lambda_handler(event, context):     client = boto3.client('appflow')        ### Google Ads     response = client.create_connector_profile(     connectorProfileName='GoogleAdsConn',     connectorType='CustomConnector',     # connectorLabel='GoogleAds',     connectionMode='Public',     connectorProfileConfig= {       "connectorProfileProperties": {           'CustomConnector': {                 # 'profileProperties': {                 #     'string': 'string'                 # },                 'oAuth2Properties': {                     'tokenUrl': 'https://oauth2.googleapis.com/token',                     'oAuth2GrantType': 'AUTHORIZATION_CODE'                     # ,'tokenUrlCustomProperties': {                     #     'string': 'string'                     # }                 }             }             },       "connectorProfileCredentials": {         "CustomConnector": {              "authenticationType": "OAUTH2",             "oauth2": {                 "accessToken": "myaccesstoken",                "clientId": "myclientid",                "clientSecret": "myclientsecret",               "oAuthRequest": {                   "authCode": "string",                  "redirectUri": "string"               },                "refreshToken": "myrefreshtoken"             }       }     }        }    )     return {         'response': response     } 

Any leads on this will be appreciated.
Thanks!

Iam trying to use gupshup whatsapp business api through template.

My template expects a link url for the attachment therefore iam building an url through buffer in nodejs and having given response type for the link url as this.

       statusCode: 200,        headers: {            "content-type": "application/pdf",            'content-disposition': 'inline; filename=suresign.pdf',            'Accept-Ranges': 'bytes',            'Content-Length': buffer.length,        },        body: buffer.toString('base64'),        isBase64Encoded: true    }``` Iam able to generate message id ```{"messageId":"8427c6aa-8140-4d79-a835-ba8f44f6c867","status":"submitted"}``` but in gupshup callback response im getting error as this ```{    "app": "SureCredsLIVE",    "timestamp": 1654016941604,    "version": 2,    "type": "message-event",    "payload": {        "id": "8427c6aa-8140-4d79-a835-ba8f44f6c867",        "type": "failed",        "destination": "918553220750",        "payload": {            "code": 1011,            "reason": "Invalid Media Size"        }    } }```