Building a serverless Web app on AWS with Amplify, CDK(python) and Nuxt(Part 1)

I love creating and writing about the creation of software.
Search for a command to run...

I love creating and writing about the creation of software.
No comments yet. Be the first to comment.
This series would feature all posts about building serverless applications with AWS amplify and CDK
Hi, Welcome to Part 2 of this post series. Here's a recap of what went down in Part 1. We covered the steps to get started in deploying an Amplify Application using AWS CDK. In this part, we will start building the full stack application using Amp...
Watch the complete Video on Youtube https://www.youtube.com/watch?v=kKX-8L_R2XM Prerequisites Before proceeding make sure you have these dependencies Docker Python 3.11 and above AWS CLI Full access to a foundation model. For this workshop, we'll...

Introduction In a previous workshop, Building event-driven applications with AWS sam and python we built an e-commerce ordering service using AWS SAM, API Gateway, Lambda and Python. Here's the solutions architecture. In that workshop, whenever a ne...

Github Repository https://github.com/EducloudHQ/introduction_to_gen_ai Skill up with serverless on Educloud https://www.educloud.academy/content/da99ad07-7efa-41e7-ba50-b18e6b89e10d This post is an introductory lesson to building AI-enhanced serverle...

Introduction Serverless computing is a cloud-based approach to application development that eliminates the need for provisioning and managing servers. Instead, developers focus on writing code that is triggered by events such as HTTP requests or data...

https://github.com/trey-rosius/sam_stepfunctions Hey!!! How you doing? In this post, we’ll look at how to build a workflow, using SAM as IaC, Appsync, and python. Prerequisites Install AWS Cli (https://docs.aws.amazon.com/cli/latest/userguide/cli-c...

Hey wassup, Welcome! I'm Rosius
In this blog series, I will be showing you how to build a serverless newspaper web application and host it to the cloud with complete continuous Integration/ continuous deployment pipelines.
We will be using AWS services such as Amplify, CDK(Cloud Development Kit), with VueJs/NuxtJs web frameworks.
The AWS Amplify Console provides a Git-based workflow for deploying and hosting fullstack serverless web applications. A fullstack serverless app consists of a backend built with cloud resources such as GraphQL or REST APIs, file and data storage, and a frontend built with single page application frameworks such as React, Angular, Vue, or Gatsby.
Build a GraphQL API on AWS with CDK, Python, AppSync, and DynamoDB
Node Package Manager (NPM), follow the instructions here to install.
npm install -g aws-cdk
Here are screenshots of the hosted application, so that you know exactly what the final product looks like.




The figure above shows the AWS services and the steps involved in deploying the application using Amplify and CDK.
The first step is to commit our application to a code repository like Gitlab, Github (1a) or AWS CodeCommit (1b)
Note: Creating Amplify application from source code in BitBucket is not currently supported using CDK. To connect to a BitBucket repository use the Amplify console.
Setup AWS CDK with python. Build and deploy the CDK code to a target AWS region to create the Amplify application.
We will use AWS Secrets Manager to store the personal access token (4b) which provides Amplify the permission to access the repository.
Amplify will generate a shareable URL that can be used to access the application from the internet. It also provides the flexibility of configuring a custom domain with SSL certificates issued by Amplify.
npx create-nuxt-app newspaperApp
I named my project newspaperApp. When the script is done running and you've set all the defaults, from the apps root directory, run it with
npm run dev
cdk init --language python
The python code for the cdk app is stored in amplify-infra-stack.py
When you initialize a python application with CDK, it comes with a virtual environment. The virtual environment serves as a host for all the dependencies of your application. This prevents dependency conflicts between your application and other applications on
your system.
In order to install the CDK amplify construct, we need to activate the virtual environment.
Run the following commands from the root directory of amplify-infra.
For MacOS
source .venv/bin/activate
For Windows
% .venv\Scripts\activate.bat
Once activated, install the amplify CDK construct by running the following command
pip install aws-cdk.aws-amplify
Also, run the following command to install all dependencies in your setup.py file
python -m pip install -r requirements.txt
Freeze your dependencies in requirements.txt
For MacOs
python -m pip freeze | grep -v '^[-#]' > requirements.txt
For Windows
python -m pip freeze | findstr /R /B /V "[-#]" > requirements.txt
Open up the project in your IDE and navigate to the amplify_infra_stack.py file.
Type in the following code
from aws_cdk import core as cdk
import aws_cdk.aws_codebuild as codebuild
import aws_cdk.aws_amplify as amplify
# For consistency with other languages, `cdk` is the preferred import name for
# the CDK's core module. The following line also imports it as `core` for use
# with examples from the CDK Developer's Guide, which are in the process of
# being updated to use `cdk`. You may delete this import if you don't need it.
from aws_cdk import core
class AmplifyInfraStack(cdk.Stack):
def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
amplify_app = amplify.App(self, "newspaper-app",
source_code_provider=amplify.GitHubSourceCodeProvider(
owner=<GITHUB-USER-NAME>,
repository=<GITHUB-REPO>,
oauth_token=cdk.SecretValue.secrets_manager(<personal access token>)),
)
amplify_app.add_branch("master")
What this piece of code does is, it'll always grab the newest commit of your application from GitHub, create a cloud formation template from it and send it to amplify console for CI/CD deployment. I'm assuming you've created a repository on Github, please replace the with a string of yours, Github repo with yours and with yours. They should all be strings.
If you don't know how to create a secret key, don't worry, I got you. It's well detailed in the article below.
Build and deploy the application to the amplify console by running
npm run build
cdk synth
cdk deploy
I'm assuming you still have your virtual environment activated.
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run generate
- npm run build
artifacts:
baseDirectory: dist
files:
- "**/*"
cache:
paths:
- node_modules/**/*
These two commands below would build and generate the folder dist which contains our deployable application.
- npm run generate
- npm run build
From the amplify-infra directory, with an activated virtual environment, run the following commands
npm run build
cdk synth
cdk deploy
Click on the provided link to view your live app. https://aws.amazon.com/blogs/mobile/deploying-a-static-website-with-aws-amplify-and-cdk/ https://docs.aws.amazon.com/cdk/latest/guide/cdk_pipeline.html