By using AWS re:Post, you agree to the Terms of Use

Questions tagged with AWS Lambda

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

AWS Greengrass lambda component hangs on python import of GreengrassCoreIPCClientV2

Hello, I am in need of some troubleshooting help. I am running Greengrassv2 and are building a lambda component. The target runtime (greengrass nucleus) runs on a raspberry pi (arm32v7). Hence I am creating the lambda deployment package in a container based on `arm32v7/python:3.9-slim-bullseye`. My lambda deployment package contains e.g. "_awscrt.cpython-39-arm-linux-gnueabihf.so" which makes me think I have made a correct compilation of the wheels. **Now to the issue I am facing** *My lambda function component works as expected* until I do an import such as `from awsiot.greengrasscoreipc.clientv2 import GreengrassCoreIPCClientV2`. When I do that the function just hangs, without errors, I have a debug printout before the import that is displayed correctly in the component log. I am running the latest version of all components, e.g. 2.7.0 of greengrass nucleus. The component configuration states "containerMode": "GreengrassContainer". I do not yet have that much debug information, since the lambda-component log is quiet and the and greengrass.log is happy pappy, its latest row just states that is has published to Local PubSub topic (which triggered my Lambda component). If I execute the lambda function in AWS I instantly receive an error: "No module named 'pycares._cares'". <---- which can be expected since the wheels are not compiled for amazon linux2 arch. *I am suspecting something about python version, I have yet to check which python version is used by greengrass at runtime. However the raspbery pi is using pyenv to set python 3.8.3 globally. And as mentioned I have compiled the lambda deployment package using python3.9. This just struck me so I will investigate this asap.* Any troubleshooting tips are very welcome.
2
answers
0
votes
52
views
asked 14 days ago

Sending Lambda generated analytics reports through email

Hi, I have a Lambda function which generates a csv and stores it in S3 each day. I want to send this across to some recipients on daily basis. The below Python code works to send a file on my local machine but I am facing challenges in getting reference to the generated file in S3 in my send mail method. Request for any pointers on this. Also, would be great if someone can guide if there any particular challenges / limits with this approach compared to using Amazon SES. I do not want to send bulk mails and would have daily deliveries to about 10-15 recipients. ``` def generateFile&Send(): ... s3 = boto3.client('s3') fileName = 's3://mybukcet/myfile' + mydatestr + '.csv' wr.s3.to_csv(final_all_data, fileName, index=False) send_mail("mymail@gmail.com", "recipient@gmail.com", emailSubject , emailText, filename , "smtpddomain.com", "587", email="mymail.com", password="mypassword", isTls=True) } def send_mail(send_from,send_to,subject,text,file,server,port,email='',password='',isTls=True): msg = MIMEMultipart() msg['From'] = send_from msg['To'] = send_to msg['Date'] = formatdate(localtime = True) msg['Subject'] = subject msg.attach(MIMEText(text)) part = MIMEBase('application', "octet-stream") part.set_payload(open(file, "rb").read()) encoders.encode_base64(part) part.add_header('Content-Disposition', 'attachment; filename=file') msg.attach(part) smtp = smtplib.SMTP(server, port) if isTls: smtp.starttls() smtp.login(email,password) smtp.sendmail(send_from, send_to, msg.as_string()) smtp.quit() ``` Regards, dbeings
2
answers
0
votes
47
views
asked 16 days ago

Why isn't my lambda function URL returning CORS headers for my preflight requests?

I am playing around with lambda function URLs, which seem like a perfect fit for my use case. I have a lambda configured with function URL turned on, Auth type of AWS_IAM, and CORS turned on with default settings (Allow Origin *, nothing else set). From Javascript running in Chrome I am sending a signed request to the lambda with code that looks like: ``` const url = new URL(rawUrl) const signer = new SignatureV4({ credentials: *******, sha256: Sha256, service: "lambda", region: region, }) const request = new HttpRequest({ hostname: url.hostname, path: url.pathname, body: JSON.stringify({}), method: 'POST', headers: { 'Content-Type': 'application/json', host: url.hostname, } }) const send = async () => { const {headers, body, method} = await signer.sign(request) console.log('send.headers', headers) const result = await fetch(rawUrl, { headers, body, method }) .then((res) => res.json()) return result } send() .then((data) => { console.log('success', data) }) .catch((reason) => { console.log('error', reason) }) ``` When this code runs it generates a request that fails CORS because the preflight is not validated. The curl equivalents of the requests Chrome is sending are ``` curl 'https://**********.lambda-url.us-west-2.on.aws/' \ -H 'sec-ch-ua: "Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'authorization: AWS4-HMAC-SHA256 Credential=*******/*******/us-west-2/lambda/aws4_request, SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date;x-amz-security-token, Signature=***********' \ -H 'Content-Type: application/json' \ -H 'x-amz-content-sha256: ************' \ -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36' \ -H 'x-amz-security-token: ********' \ -H 'Referer: http://localhost:3000/' \ -H 'x-amz-date: 20220916T035331Z' \ -H 'sec-ch-ua-platform: "macOS"' \ --data-raw '{}' \ --compressed ``` for the request and ``` curl 'https://*******.lambda-url.us-west-2.on.aws/' \ -X 'OPTIONS' \ -H 'Accept: */*' \ -H 'Accept-Language: en-US,en;q=0.9' \ -H 'Access-Control-Request-Headers: authorization,content-type,x-amz-content-sha256,x-amz-date,x-amz-security-token' \ -H 'Access-Control-Request-Method: POST' \ -H 'Connection: keep-alive' \ -H 'Origin: http://localhost:3000' \ -H 'Referer: http://localhost:3000/' \ -H 'Sec-Fetch-Dest: empty' \ -H 'Sec-Fetch-Mode: cors' \ -H 'Sec-Fetch-Site: cross-site' \ -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36' \ -H 'dnt: 1' \ -H 'sec-gpc: 1' \ --compressed ``` for the preflight. If I run that preflight in a terminal I get the following response: ``` HTTP/1.1 200 OK Date: Fri, 16 Sep 2022 03:41:24 GMT Content-Type: application/json Content-Length: 0 Connection: keep-alive x-amzn-RequestId: 80fc5a73-6f60-4315-b0bf-f3a63c7e6050 ``` Note that there aren't valid CORS headers being sent back, which results in Chrome not making the actual request. If I run the request itself in a terminal and bypass the preflight, then it runs successfully. Is there an error in the way that I am making a request or how I've configured the lambda (I've tried various combinations)? Thanks for your help!
2
answers
0
votes
35
views
profile picture
asked 18 days ago