'Can't access google cloud client on AWS Lambda

I'm tring to make a AWS Lambda function receives a file from google cloud storage to process and insert to AWS RDS DB.

I set my lambda handler like this:

import json
from google.cloud import storage

def lambda_handler(event, context):
    storage_client = storage.Client()
    bucket_name = 'my-bucket-name'
    blobs = storage_client.list_blobs(bucket_name)
    for blob in blobs:
        print(blob.name)
    return {
        'statuscode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Also I set my env var like this: GOOGLE_APPLICATION_CREDENTIALS: serviceAccountKey.json

This key is from google cloud storage service account(make private account key)

If i run this code on local vscode, it works.

However on aws lambda, it doesn't works.

Test Event Name
saveRequestEvent

Response
{
    "errormessage": "2022-03-08T22:46:40.714Z fed88616-fbf6-48ca-998f-8accbab756aa Task timed out after 30.03 seconds"
}

Is there any problem on my code? Or need to set firewall options?

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source