-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (74 loc) · 2.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/rekognition"
)
type Request struct {
Bucket string `json:"bucket"`
Name string `json:"name"`
}
type Response struct {
Labels []*rekognition.Label `json:"Labels"`
}
func Handler(request Request) (Response, error) {
sess, err := session.NewSession(&aws.Config{
Region: aws.String("us-east-1"),
})
svc := rekognition.New(sess)
fmt.Printf("Bucket: %s\n", request.Bucket)
fmt.Printf("Name: %s\n", request.Name)
input := &rekognition.DetectLabelsInput{
Image: &rekognition.Image{
S3Object: &rekognition.S3Object{
Bucket: aws.String(request.Bucket),
Name: aws.String(request.Name),
},
},
MaxLabels: aws.Int64(123),
MinConfidence: aws.Float64(70.000000),
}
result, err := svc.DetectLabels(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidS3ObjectException:
fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeImageTooLargeException:
fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeInvalidImageFormatException:
fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return Response{}, err
}
return Response{Labels: result.Labels}, nil
}
func main() {
// bucket := os.Args[1]
// name := os.Args[2]
// resp, err := Handler(Request{Bucket: bucket, Name: name})
// if err == nil {
// fmt.Println(resp)
// }
lambda.Start(Handler)
}