-
Notifications
You must be signed in to change notification settings - Fork 1
/
invocations.go
102 lines (73 loc) · 2.53 KB
/
invocations.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package lambda_go_sdk
import (
"encoding/json"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/lambda"
)
func invokeRenderLambda(options RemotionOptions) (*RemotionRenderResponse, error) {
// Create a new AWS session
sess := session.Must(session.NewSessionWithOptions(session.Options{
Config: aws.Config{Region: aws.String(options.Region)},
SharedConfigState: session.SharedConfigEnable,
}))
// Create a new Lambda client
svc := lambda.New(sess)
internalParams, validateError := constructRenderInternals(&options)
if validateError != nil {
return nil, validateError
}
internalParamJsonObject, marshallingError := json.Marshal(internalParams)
if marshallingError != nil {
return nil, marshallingError
}
invocationPayload := &lambda.InvokeInput{
FunctionName: aws.String(options.FunctionName),
Payload: internalParamJsonObject,
}
// Invoke Lambda function
invocationResult, invocationError := svc.Invoke(invocationPayload)
if invocationError != nil {
return nil, invocationError
}
// Unmarshal response from Lambda function
var renderResponseOutput RemotionRenderResponse
responseMarshallingError := json.Unmarshal(invocationResult.Payload, &renderResponseOutput)
if responseMarshallingError != nil {
return nil, responseMarshallingError
}
return &renderResponseOutput, nil
}
func invokeRenderProgressLambda(config RenderConfig) (*RenderProgress, error) {
// Create a new AWS session
sess := session.Must(session.NewSessionWithOptions(session.Options{
Config: aws.Config{Region: aws.String(config.Region)},
SharedConfigState: session.SharedConfigEnable,
}))
// Create a new Lambda client
svc := lambda.New(sess)
internalParams, validateError := constructGetProgressInternals(&config)
if validateError != nil {
return nil, validateError
}
internalParamsJSON, marshallingError := json.Marshal(internalParams)
if marshallingError != nil {
return nil, marshallingError
}
invocationParams := &lambda.InvokeInput{
FunctionName: aws.String(config.FunctionName),
Payload: internalParamsJSON,
}
// Invoke Lambda function
invokeResult, invokeError := svc.Invoke(invocationParams)
if invokeError != nil {
return nil, invokeError
}
// Unmarshal response from Lambda function
var renderProgressOutput RenderProgress
resultUnmarshallError := json.Unmarshal(invokeResult.Payload, &renderProgressOutput)
if resultUnmarshallError != nil {
return nil, resultUnmarshallError
}
return &renderProgressOutput, nil
}