Building an Unsplash 2023 Recap using Golang, AWS Lambda, Redis and React
In this tutorial, we'll build a Unsplash 2023 Recap. Unsplash has been a hub of creativity throughout 2023, showcasing the world's most captivating moments through the lens of talented photographers. As we come to the end of the year I wanted to show photographers their recap of the year.
Demo
You can see the deployed demo of the project here
Technologies Used
Unsplash API for Data Retrieval
The Unsplash API will serve as the primary data source for our application. We'll utilize the Unsplash API to fetch user data, photo information, and statistics, including views, likes, and downloads. Unsplash's API is one of the most popular APIs, with over 1 billion requests per month.
Golang for Efficient Backend Magic
Golang, known for its efficiency and concurrency model, will serve as the backbone of our application. Its robust standard library and performance characteristics make it an ideal choice for handling data processing and communication between various components.
Serverless Architecture with AWS Lambda
We'll embrace the serverless paradigm by utilizing AWS Lambda to effortlessly scale our application based on varying workloads. This allows us to focus on the core functionality without the hassle of managing servers, ensuring a seamless experience for users.
Upstash Redis for Lightning-Fast Data Retrieval
Upstash Redis, a cloud service focusing on simplicity and scalability, will be our cache layer for storing and retrieving user-specific data. Its high performance and low latency make it an excellent choice for our application, ensuring a smooth user experience. It will also enable us to reduce the number of API calls to the Unsplash API.
React and Tailwind for Stunning Frontend
On the frontend, we'll leverage React for its component-based architecture and efficient rendering. Tailwind CSS will add the finishing touch, providing a utility-first styling approach that ensures rapid development without compromising design flexibility.
Let's Dive In!
Prerequisites
Before we begin, make sure you have the following:
- Unsplash API account and credentials.
- Golang environment set up.
- AWS Lambda account and credentials.
- Upstash account and Upstash Redis database.
- Node.js and npm installed for React development.
- Vercel account for React deployment.
Creating Unsplash Account and App in Unsplash API Dashboard
1. Create Unsplash Account
Start by creating an Unsplash account at https://unsplash.com/join.
2. Create Unsplash App
Next, create an Unsplash app in the Unsplash API dashboard. This will provide you with the necessary credentials to access the Unsplash API.
Setting Up the Backend with Golang and AWS Lambda
1. Create a Golang Lambda Function
Start by creating a new Golang Lambda function using the AWS Lambda Go SDK.
2. Create an AWS Account
Start by creating an AWS account at https://aws.amazon.com/.
3. Create an AWS Lambda Function
Create an AWS Lambda function through the AWS Lambda console.
4. Deploy Golang Lambda Function
Build your Golang Lambda function and deploy it to AWS Lambda using either the AWS CLI or the AWS Lambda console.
Note: You can find more information about building Go executables for AWS Lambda here.
Integrating Unsplash API in Golang
Update your Golang Lambda function to include Unsplash API integration for fetching user data and photo statistics.
Upstash Redis Integration
1. Create Upstash Account
Start by creating an Upstash account at https://console.upstash.com/login.
2. Create Upstash Redis Database
Create an Upstash Redis database through the console and obtain the connection URL and password.
3. ###Integrate Upstash Redis in Golang
Update your Golang Lambda function to include Upstash Redis integration for storing and retrieving user-specific data.
You can either use a redis library or use REST API of Upstash.
In this tutorial, we will use REST API of Upstash. Because it is more convenient for serverless applications.
4. Get Data
5. Get Data
Building the Frontend with React and Tailwind
1. Initialize React App
Set up a new React app using Create React App.
2. Tailwind CSS Integration
Install Tailwind CSS and configure it in your React project.
3. Create Photo Component
Develop a React component to display user's top 5 photos, including views, likes, and downloads.
4. Fetch Data from Golang Lambda
Implement logic to fetch data from the Golang Lambda function in your React app.
Bringing It All Together
1. Connect Frontend and Backend
Update the React app to make API calls to the Golang Lambda function for fetching user data and photo statistics.
2. Styling with Tailwind
Style your React components using Tailwind CSS utility classes for a visually appealing and responsive design.
3. Deploy React App
Deploy your React app to a hosting platform of your choice in our case we will use Vercel. Which you can easily deploy your app by connecting your GitHub repository.
Source Codes
You can find the complete source codes below:
Lambda Function
React App
Conclusion
In this tutorial, we’ve covered the integration of Golang, Upstash Redis, AWS Lambda and Unsplash API to build a Unsplash 2023 Recap.
If you enjoyed this tutorial, be sure to check out our other tutorials on the Upstash blog.
If you have any questions or comments, feel free to reach out to me on GitHub or LinkedIn.
Closing Notes
-
Your Unsplash demo app has 50 request limit per hour. You can increase this limit by applying for a production. Remember to follow the Unsplash API guidelines when using the API.
-
If you expose lambda as function url, you have to set use following format for response body in order to get a valid response from AWS Lambda. More info
-
Your Lambda handler name should be the same as your executable name. In our case, it is
main
. More info