How to Send Digital Products Easily Using Tally Forms and AWS Amplify Gen 2
It's 2024. Fulfilling an online order shouldn't require signing up for a whole SaaS provider.
Table of contents
Whether it's signing up to receive a free e-book, having folks register for an event, or any other of the many reasons, emailing your customers/users a product when they submit a form is a very common task. So why isn't it easier?
In this post, I'll walk through how to quickly get an application setup with Tally forms and extend it into the AWS ecosystem via webhooks. This will allow us to build out an app that can email a digital product to our users after it's fetched from an S3 bucket.
Application Overview
The frontend is fairly simple. Essentially, give a form created by Tally, a user can fill it out and through the use of Tally webhooks, our Lambda function can be triggered.
The backend is architected using Amplify Gen 2 and simply creates a Lambda function, and an S3 bucket.
The repository for this project contains all of the code needed to get this working:
The core logic for this application is primarily to get the item from S3 as a presigned URL, and then to send an <a>
tag with the href
value set to the presigned URL:
// Get the song url from S3
const url = await generatePresignedURL(
env.SONG_STORAGE_BUCKET_NAME,
env.SONG_PATH,
3600 //expires in 1 hour
)
// Send email with the song
await sendHTMLEmail(
env.VERIFIED_SES_FROM_EMAIL,
[email],
'Your song has arrived!',
`
<html>
<body>
<h1>Hello from Focus Otter Music!</h1>
<p>Hey ${firstName}, thanks so much for your purchase!</p>
<p>Here is <a href="${url}">your song</a>. Hope you enjoy!</p>
</body>
</html>
`
)
Conclusion
This is a great starter project for those wanting to get into AWS. However, there are times where the file you'd like to send may be too large to embed in the body of the file. For those cases, you'll want to send it as an attachment. Fortunately, I have a blog post setup that walks through exactly how to do that as well!