Hello there, I want to discuss a fascinating subject with you all. That about sums up how to install our Angular application in AWS S3. To efficiently and affordably offer static web content to visitors all around the world, host your Angular application on AWS S3. You will learn how to host your Angular application on an AWS S3 bucket in this article.
Step 1:
Build Your Angular Application
Ensure you have Angular CLI installed: If not, install it globally using following command.
npm install -g @angular/cli
Navigate to your Angular app’s root directory in the terminal.
Run the command that showing below to build the production-ready version of your app.
ng build --prod
Step 2:
Create an AWS S3 Bucket to deploy our angular application.
- Log in to your AWS Management Console.
- Navigate to the S3 service.
- And after navigating into service click “Create bucket” and follow the prompts to create the bucket.
- Choose a unique name, region, and configure the settings as your wish.
Step 3:
Upload Your Angular App to the S3 Bucket.
- After creating your bucket in AWS S3, click on it to open its details.
- Click the “Upload” section and select the files
dist
folder of your Angular application. - And then upload the files to the root of your S3 bucket.
Step 4:
Configure Bucket Properties
- In the bucket properties, go to the “Static website hosting” section.
- Select “Use this bucket to host a website.”
- Enter
index.html
as both the Index and Error Document.
Step 5:
Set Permissions
- In the bucket properties, navigate to the “Permissions” tab.
- Under “Bucket Policy,” click “Edit.”
- Add a bucket policy to make your content publicly readable. Example policy:
{ "Version": "2012-10-17",
"Statement": [
{"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"}
]
}
- Replace
YOUR_BUCKET_NAME
with your actual bucket name.
Step 6:
Configure DNS (Optional)
- If you have a custom domain, navigate to your domain registrar’s settings.
- Create a CNAME record pointing to your S3 bucket’s website endpoint.
- This step allows you to use your own domain for your hosted Angular app.
Step 7:
Access Your Angular App
After following the above steps, your Angular app should be accessible via the provided S3 bucket URL or your custom domain.
Conclusion:
Serving static material to visitors through your Angular application is made scalable and reliable by hosting it on AWS S3. You can easily and cheaply put up your Angular app for worldwide access by following these detailed instructions. Hope you guys got a good understanding of it and follow me for more.