Triggering renders from Go
EXPERIMENTAL
This feature is new. Please report any issues you encounter.
To trigger a Lambda render using Go, you can use the Remotion Lambda Go client. Note the following:
- You first need to complete the Lambda setup.
- Sending large input props (>200KB) is not supported with Go at the moment.
- Always match the version of the Go client with the version of the Lambda function you deployed. Otherwise, calls will fail due to version mismatch!
main.gogo
package mainimport ("fmt""log""os""github.com/go-playground/validator/v10""github.com/joho/godotenv""github.com/remotion-dev/lambda_go_sdk")type ValidationError struct {Field stringMessage string}func msgForTag(fe validator.FieldError) string {switch fe.Tag() {case "required":return "This field is required"}return fe.Error() // default error}func main() {// Load the environment variables from the .env fileerr := godotenv.Load()if err != nil {log.Fatal(err)}// Specify the URL to your Webpack bundleserveUrl := os.Getenv("REMOTION_APP_SERVE_URL")// Specify the function you would like to callfunctionName := os.Getenv("REMOTION_APP_FUNCTION_NAME")// Specify the region you deployed to, for example "us-east-1"region := os.Getenv("REMOTION_APP_REGION")// Set parameters for renderrenderInputRequest := lambda_go_sdk.RemotionOptions{ServeUrl: serveUrl,FunctionName: functionName,Region: region,// The data that composition will useInputProps: map[string]interface{}{"data": "Let's play",},Composition: "main", // The composition to use}// Execute the render processrenderResponse, renderError := lambda_go_sdk.RenderMediaOnLambda(renderInputRequest)// Check if there are validation errorsif renderError != nil {validationOut := make([]ValidationError, len(renderError.(validator.ValidationErrors)))for i, fieldError := range renderError.(validator.ValidationErrors) {validationOut[i] = ValidationError{fieldError.Field(), msgForTag(fieldError)}}for _, apiError := range validationOut {fmt.Printf("%s: %s\n", apiError.Field, apiError.Message)}return}fmt.Print(renderResponse.RenderId)/// Get bucket informationfmt.Printf("bucketName: %s\nRenderId: %s\n", renderResponse.RenderId, renderResponse.RenderId)// Render Progress requestrenderProgressInputRequest := lambda_go_sdk.RenderConfig{FunctionName: functionName,Region: region,RenderId: renderResponse.RenderId,BucketName: renderResponse.BucketName,}// Execute getting the render progressrenderProgressResponse, renderProgressError := lambda_go_sdk.GetRenderProgress(renderProgressInputRequest)// Check if we have errorif renderProgressError != nil {log.Fatalf("%s %s", "Invalid render progress response", renderProgressError)}// Get the overall render progressfmt.Printf("overallprogress: %f ", renderProgressResponse.OverallProgress)}
main.gogo
package mainimport ("fmt""log""os""github.com/go-playground/validator/v10""github.com/joho/godotenv""github.com/remotion-dev/lambda_go_sdk")type ValidationError struct {Field stringMessage string}func msgForTag(fe validator.FieldError) string {switch fe.Tag() {case "required":return "This field is required"}return fe.Error() // default error}func main() {// Load the environment variables from the .env fileerr := godotenv.Load()if err != nil {log.Fatal(err)}// Specify the URL to your Webpack bundleserveUrl := os.Getenv("REMOTION_APP_SERVE_URL")// Specify the function you would like to callfunctionName := os.Getenv("REMOTION_APP_FUNCTION_NAME")// Specify the region you deployed to, for example "us-east-1"region := os.Getenv("REMOTION_APP_REGION")// Set parameters for renderrenderInputRequest := lambda_go_sdk.RemotionOptions{ServeUrl: serveUrl,FunctionName: functionName,Region: region,// The data that composition will useInputProps: map[string]interface{}{"data": "Let's play",},Composition: "main", // The composition to use}// Execute the render processrenderResponse, renderError := lambda_go_sdk.RenderMediaOnLambda(renderInputRequest)// Check if there are validation errorsif renderError != nil {validationOut := make([]ValidationError, len(renderError.(validator.ValidationErrors)))for i, fieldError := range renderError.(validator.ValidationErrors) {validationOut[i] = ValidationError{fieldError.Field(), msgForTag(fieldError)}}for _, apiError := range validationOut {fmt.Printf("%s: %s\n", apiError.Field, apiError.Message)}return}fmt.Print(renderResponse.RenderId)/// Get bucket informationfmt.Printf("bucketName: %s\nRenderId: %s\n", renderResponse.RenderId, renderResponse.RenderId)// Render Progress requestrenderProgressInputRequest := lambda_go_sdk.RenderConfig{FunctionName: functionName,Region: region,RenderId: renderResponse.RenderId,BucketName: renderResponse.BucketName,}// Execute getting the render progressrenderProgressResponse, renderProgressError := lambda_go_sdk.GetRenderProgress(renderProgressInputRequest)// Check if we have errorif renderProgressError != nil {log.Fatalf("%s %s", "Invalid render progress response", renderProgressError)}// Get the overall render progressfmt.Printf("overallprogress: %f ", renderProgressResponse.OverallProgress)}
Changelog
v4.0.6
: The response payload structure has changed. See the history of this page to see the previous structure.