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. Reference AWS Documentation Installing the new SDK and removing the previous SDK I changed the SDK dependency from V1 to V2. Reference: - + 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... 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; - services.AddAWSService(); + services.AddAWSService(); - private readonly IAmazonSimpleEmailService _amazonSimpleEmailService; + private readonly IAmazonSimpleEmailServiceV2 _amazonSimpleEmailService; - _amazonSimpleEmailService = new AmazonSimpleEmailServiceClient(region); + _amazonSimpleEmailService = new AmazonSimpleEmailServiceV2Client(region); Complete changes, you may refer to these commits changes. Examine the result Duration: 12664.70 ms Billed Duration: 12665 ms Memory Size: 512 MB Max Memory Used: 322 MB Init Duration: 567.43 ms 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. Most likely, I lost some metadata after uploading the file. Which is not the case when I use the temporary link. I'll try to find out later. :(

Apr 27, 2025 - 15:42
 0
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:
-    
+    

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;
-            services.AddAWSService();
+            services.AddAWSService();
-        private readonly IAmazonSimpleEmailService _amazonSimpleEmailService;

+        private readonly IAmazonSimpleEmailServiceV2 _amazonSimpleEmailService;

-            _amazonSimpleEmailService = new AmazonSimpleEmailServiceClient(region);

+            _amazonSimpleEmailService = new AmazonSimpleEmailServiceV2Client(region);

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    

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. Most likely, I lost some metadata after uploading the file. Which is not the case when I use the temporary link.

Blank Pages

I'll try to find out later. :(

Sad GIF