我正在尝试使用DeepLens Lambda函数将图像上传到S3。我从this tutorial获得了用于上传的代码。
private async void OnSomethingPressed(...)
{
await Task.Run(() => RunProcessAndWait());
// Do UI (or other) things here
}
但是,我不断收到错误消息:
// Note the small changes to your script
// Take the token:
$infoToken = file_get_contents('http://192.168.8.1/api/webserver/token');
$xml = new simpleXMLElement($infoToken)
$token = $xml->token;
$content ="";
$lengContent = strlen($content);
$dateTime = date("Y-m-d H:i:s");
$headers = array(
"__RequestVerificationToken: $token",
"X-Requested-With: XMLHttpRequest",
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8"
);
$data ='<?xml version="1.0" encoding="UTF-8"?><request><Index>-1</Index><Phones><Phone>777777</Phone></Phones><Sca></Sca><Content>'.$content.'</Content><Length>'.$lengContent.'</Length><Reserved>1</Reserved><Date>'.$dateTime.'</Date></request>' ;
//connect with cURL
//http://192.168.8.1/api/send-sms : Unapprove URL;
//http://192.168.8.1/api/sms/send-sms : Approve URL;
$curl = curl_init('http://192.168.8.1/api/sms/send-sms');
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
$content = curl_exec($curl);
var_dump($content);
curl_close($curl);
// Problem solved
我创建了一个IAM角色,并将其附加到Deeplens lambda函数上,并附加了以下策略:AWSDeepLensLambdaFunctionAccessPolicy,AWSLambdaExecute,AWSDeepLensServiceRolePolicy,AmazonS3FullAccess和具有以下JSON的自定义策略:
def write_image_to_s3(img):
session = Session()
s3 = session.create_client('s3')
file_name = 'DeepLens/face.jpg'
encode_param=[int(cv2.IMWRITE_JPEG_QUALITY),90]
_, jpg_data = cv2.imencode('.jpg', img, encode_param)
response = s3.put_object(ACL='public-read-write', Body=jpg_data.tostring(),Bucket='MY-BUCKET-NAME',Key=file_name)
image_url = 'https://s3.amazonaws.com/MY-BUCKET-NAME/'+file_name
return image_url
我什至通过访问控制列表为存储桶提供了公共访问权限:
并使桶策略公开:
Error in face detection lambda: An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
(我知道公开存储桶是个坏主意)