DEV Community

Cover image for Migrating from Amazon Simple Email Service API V1 to V2
1 1

Migrating from Amazon Simple Email Service API V1 to V2

I'm interested in the new feature that allows me to send attachments in my email. Previously, my flow sent the temporary public link to see the result of my merged PDF. However, it may not be the case!

So, I'll try to move to the V2 API.

Hooray GIF

Reference

Installing the new SDK and removing the previous SDK

I changed the SDK dependency from V1 to V2.

  • Reference:
-    <PackageReference Include="AWSSDK.SimpleEmail" Version="3.7.402.82" />
+    <PackageReference Include="AWSSDK.SimpleEmailV2" Version="3.7.410.12" />
Enter fullscreen mode Exit fullscreen mode

Changing the code

Previously, I had a feature flag for using HTML format. However, I will remove it and use the HTML format as the default. You may refer to my previous session regarding the feature flag presentation. I haven't written it yet. Please let me know if you want me to share it. Previously limited to AWS Commnity Indonesia event.

Bervianto Leo Pratama's Speaker Profile @ Sessionize

Passionate Software Engineer who loves to learn DevOps, Microservices, and Cloud Computing...

favicon sessionize.com

Let's focus on the required changes. I've added some improvements to my repository for readability.

  • Updating the reference from V1 to V2.
- using Amazon.SimpleEmail;
+ using Amazon.SimpleEmailV2;
- using Amazon.SimpleEmail.Model;
+ using Amazon.SimpleEmailV2.Model;
Enter fullscreen mode Exit fullscreen mode
-            services.AddAWSService<IAmazonSimpleEmailService>();
+            services.AddAWSService<IAmazonSimpleEmailServiceV2>();
Enter fullscreen mode Exit fullscreen mode
-        private readonly IAmazonSimpleEmailService _amazonSimpleEmailService;

+        private readonly IAmazonSimpleEmailServiceV2 _amazonSimpleEmailService;

-            _amazonSimpleEmailService = new AmazonSimpleEmailServiceClient(region);

+            _amazonSimpleEmailService = new AmazonSimpleEmailServiceV2Client(region);
Enter fullscreen mode Exit fullscreen mode

Complete changes, you may refer to these commits changes.

Examine the result

Run Duration and Memory

Duration: 12664.70 ms   Billed Duration: 12665 ms   Memory Size: 512 MB Max Memory Used: 322 MB Init Duration: 567.43 ms    
Enter fullscreen mode Exit fullscreen mode

Well, of course, there are some side effects.

  • First, long running duration. So, it means increase the billing! I'll evaluate this change; if needed, I will move the operation (sending the attachment) to another service.
  • Second, the memory used is increasing. Well, it's expected, because I will need to download the whole PDF to my Lambda. Of course, I may need to move the workload or reuse the merged file. So, it's not only uploading to the S3, but also using the file for the attachment. Currently, I use a bad approach, which downloads the uploaded file into S3, which increases the network call. The better approach is to reopen the file and upload it again.

However, I'll still evaluate the current state. When necessary, I'll do more enhancements to my existing environment. So, at least, I will need to reduce the workload time.

Note:

  • Sadly, my attachment (the PDF) gives multiple blank pages. Not sure of the root cause, having some cases. I checked the result in the S3 bucket itself. I can open it as expected. Either the wrong download process or the wrong encoding process. I noticed the file size is quite different from the original file size.

Blank Pages

I'll try to find out later. :(

Sad GIF

Embedded BI Dashboards are 💩 Building them yourself is 💩

Embedded BI Dashboards are 💩 Building them yourself is 💩

Use our developer toolkit to build fast-loading, native-feeling dashboards for your customers (without the sh*t).

Get early access

Top comments (0)

Create a simple OTP system with AWS Serverless cover image

Create a simple OTP system with AWS Serverless

Implement a One Time Password (OTP) system with AWS Serverless services including Lambda, API Gateway, DynamoDB, Simple Email Service (SES), and Amplify Web Hosting using VueJS for the frontend.

Read full post

👋 Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay