Open and save Presentation in AWS Lambda
4 Feb 20254 minutes to read
Syncfusion® PowerPoint is a .NET Core PowerPoint library used to create, read, edit and convert PowerPoint documents programmatically without Microsoft PowerPoint or interop dependencies. Using this library, you can open and save Presentation in AWS Lambda.
Steps to open and save Presentation in AWS Lambda
Step 1: Create a new AWS Lambda project as follows.

Step 2: Select Blueprint as Empty Function and click Finish.

Step 3: Install the Syncfusion.Presentation.Net.Core NuGet package as a reference to your project from NuGet.org.

NOTE
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, you also have to add “Syncfusion.Licensing” assembly reference and include a license key in your projects. Please refer to this link to know about registering Syncfusion® license key in your application to use our components.
Step 4: Create a folder and copy the required data files and include the files to the project.

Step 5: Set the copy to output directory to Copy if newer to all the data files.

Step 6: Include the following namespaces in Function.cs file.
using Syncfusion.Presentation;step 7: Add the following code snippet in Function.cs to open a Presentation in AWS Lambda.
string filePath = Path.GetFullPath(@"Data/Template.pptx");
using IPresentation pptxDoc = Presentation.Open(filePath);Step 8: Add below code snippet demonstrates accessing a shape from a slide and changing the text within it.
//Get the first slide from the PowerPoint presentation.
ISlide slide = pptxDoc.Slides[0];
//Get the first shape of the slide.
IShape shape = slide.Shapes[0] as IShape;
//Change the text of the shape.
if (shape.TextBody.Text == "Company History")
shape.TextBody.Text = "Company Profile";Step 9: Add below code example to save the Presentation in AWS Lambda.
//Save the PowerPoint file.
MemoryStream stream = new MemoryStream();
pptxDoc.Save(stream);
return Convert.ToBase64String(stream.ToArray());Step 10: Right-click the project and select Publish to AWS Lambda.

Step 11: Create a new AWS profile in the Upload Lambda Function Window. After creating the profile, add a name for the Lambda function to publish. Then, click Next.

Step 12: In the Advanced Function Details window, specify the Role Name as based on AWS Managed policy. After selecting the role, click the Upload button to deploy your application.

Step 13: After deploying the application, you can see the published Lambda function in AWS console.

Step 14: Edit Memory size and Timeout as maximum in General configuration of the AWS Lambda function.

Steps to post the request to AWS Lambda
Step 1: Create a new console project.

step 2: Install the following Nuget packages in your application from Nuget.org.
Step 3: Include the following namespaces in Program.cs file.
using Amazon;
using Amazon.Lambda;
using Amazon.Lambda.Model;
using Newtonsoft.Json;Step 4: Add the following code snippet in Program.cs to invoke the published AWS Lambda function using the function name and access keys.
//Create a new AmazonLambdaClient
AmazonLambdaClient client = new AmazonLambdaClient("awsaccessKeyID", "awsSecreteAccessKey", RegionEndpoint.USEast2);
//Create new InvokeRequest with published function name.
InvokeRequest invoke = new InvokeRequest
{
FunctionName = "MyNewFunction",
InvocationType = InvocationType.RequestResponse,
Payload = "\"Test\""
};
//Get the InvokeResponse from client InvokeRequest.
InvokeResponse response = client.Invoke(invoke);
//Read the response stream
var stream = new StreamReader(response.Payload);
JsonReader reader = new JsonTextReader(stream);
var serilizer = new JsonSerializer();
var responseText = serilizer.Deserialize(reader);
//Convert Base64String into PowerPoint document
byte[] bytes = Convert.FromBase64String(responseText.ToString());
FileStream fileStream = new FileStream("Sample.pptx", FileMode.Create);
BinaryWriter writer = new BinaryWriter(fileStream);
writer.Write(bytes, 0, bytes.Length);
writer.Close();
System.Diagnostics.Process.Start("Sample.pptx");By executing the program, you will get the PowerPoint document as follows.

From GitHub, you can download the console application and AWS Lambda project.
Click here to explore the rich set of Syncfusion® PowerPoint Library (Presentation) features.

