Skip to content

Commit 36d6c5a

Browse files
committed
Added publicPath and readme file
1 parent 28c2f92 commit 36d6c5a

2 files changed

Lines changed: 218 additions & 0 deletions

File tree

learnings/aws-learnings.md

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
🚀 Hosting React/Vue Microfrontend on AWS S3
2+
3+
Follow these steps to host your frontend app on Amazon S3:
4+
5+
1. Create an S3 Bucket
6+
7+
- Go to the AWS Console → search for S3.
8+
9+
- Click Create bucket.
10+
11+
- Enter a unique bucket name (e.g., `my-mfe-container`).
12+
13+
- Leave all other fields as default → click Create bucket.
14+
15+
2. Enable Static Website Hosting
16+
17+
- Open your newly created bucket.
18+
19+
- Go to the Properties tab.
20+
21+
- Scroll down to Static website hosting.
22+
23+
- Click Edit → enable Host a static website.
24+
25+
- Set the Index document to:
26+
27+
```js
28+
index.html
29+
```
30+
- Save changes.
31+
32+
3. Update Bucket Permissions
33+
34+
- Go to the Permissions tab of your bucket.
35+
36+
- Click Edit under Block public access settings.
37+
38+
- Uncheck Block all public access.
39+
40+
- Confirm and Save changes.
41+
42+
**🔑 Configure Bucket Policy for CloudFront Access**
43+
44+
To allow CloudFront (or public access) to fetch files from your S3 bucket, update the bucket policy:
45+
46+
1. Open Bucket Policy Editor
47+
48+
- Go to your S3 bucket → Permissions tab.
49+
50+
- Scroll to Bucket policy → click Edit.
51+
52+
2. Use Policy Generator
53+
54+
- Click Policy generator to create a policy.
55+
56+
- Choose:
57+
58+
- Policy Type: `S3 Bucket Policy`
59+
60+
- Principal: `*` (allows public access)
61+
62+
- Actions: `GetObject`
63+
64+
- Resource (ARN):
65+
66+
- Copy the ARN of your bucket (from the same page).
67+
68+
- Append `/*` to allow access to all files inside the bucket.
69+
70+
- Example:
71+
72+
```ruby
73+
74+
arn:aws:s3:::my-mfe-container/*
75+
76+
```
77+
⚠️ If adding ARN with `/*` doesn’t work, you can:
78+
79+
- Select `*` (all resources) in the policy generator.
80+
81+
- Generate the policy JSON.
82+
83+
- Then manually replace `"Resource": "*"` with your correct bucket ARN (with `/*`).
84+
85+
3. Generate & Apply Policy
86+
87+
- Click Add StatementGenerate Policy.
88+
89+
- Copy the generated JSON.
90+
91+
- Paste it into the Bucket policy editor.
92+
93+
- Save changes.
94+
95+
96+
```js
97+
**Notes on CloudFront UI Updates**
98+
99+
Before setting up a CloudFront distribution, be aware that the AWS UI has changed slightly compared to older tutorials or videos. Here are the key differences:
100+
101+
1. Delivery Method
102+
103+
- Previously, you had to choose between Web and RTMP.
104+
105+
- The RTMP option has been removed, so CloudFront now defaults to Web delivery. No manual selection is required.
106+
107+
2. Distribution Settings
108+
109+
- What was earlier called “Distribution settings” is now simply labeled “Settings.”
110+
111+
3. SSL Certificate
112+
113+
- The SSL certificate fields look different.
114+
115+
- You won’t see the default CloudFront certificate explicitly shown, but rest assured, the default certificate is still applied automatically—no action needed.
116+
```
117+
118+
**🚀 Setting up CloudFront Distribution**
119+
120+
1. Open CloudFront
121+
122+
- In the AWS Console, open a new tab.
123+
124+
- Search for CloudFront and click on it.
125+
126+
2. Create Distribution
127+
128+
- Click on Create distribution.
129+
130+
- If prompted, switch to the previous version of the create distribution page (UI option).
131+
132+
3. Configure Origin
133+
134+
- In the Origin domain field, select your S3 bucket name.
135+
136+
4. Default Cache Behavior Settings
137+
138+
- Scroll down to Viewer protocol policy.
139+
140+
- Select Redirect HTTP to HTTPS (ensures all traffic is served securely).
141+
142+
5. Finalize Distribution
143+
144+
- Review settings.
145+
146+
- Click Create distribution.
147+
148+
🔧 Configure Root Object & Error Handling
149+
150+
1. Set Default Root Object
151+
152+
- Once the distribution is created, click on your distribution ID.
153+
154+
- Go to the General tab.
155+
156+
- Click the Edit icon.
157+
158+
- In the Default root object field, enter:
159+
160+
```bash
161+
162+
container/latest/index.html
163+
164+
```
165+
- Save changes.
166+
167+
2. Configure Custom Error Response
168+
169+
- Navigate to the Error pages tab.
170+
171+
- Click Create custom error response.
172+
173+
- In the HTTP error code dropdown, select 403: Forbidden.
174+
175+
- Enable Customize error response (check Yes).
176+
177+
- Set Response page path to:
178+
179+
```bash
180+
181+
/container/latest/index.html
182+
183+
```
184+
- Set HTTP response code to 200 OK.
185+
186+
- Click Create custom error response.
187+
188+
189+
**Create an IAM User for AWS Deployment Keys**
190+
191+
1. Open a new tab in the AWS Console.
192+
193+
2. In the search bar, type IAM and open the IAM service.
194+
195+
3. From the left sidebar, click Usersthen click Create user.
196+
197+
4. Enter a username (e.g., mfe-github-action) and click Next.
198+
199+
5. On the Permissions step, select Attach policies directly.
200+
201+
- Search for AmazonS3FullAccess and check it.
202+
203+
- Search for CloudFrontFullAccess and check it.
204+
205+
6. Click Next, review the details, then click Create user.
206+
207+
7. From the list of users, select the newly created user.
208+
209+
8. Go to the Security credentials tab.
210+
211+
9. Scroll down to the Access keys section → click Create access key.
212+
213+
10. Choose Command Line Interface (CLI) as the use case.
214+
215+
11. Tick the I understand... confirmation box, then click Next.
216+
217+
12. Copy and/or download the Access Key ID and Secret Access Key — these will be used for your GitHub Actions deployment.

packages/container/config/webpack.prod.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const prodConfig = {
99
mode: 'production',
1010
output:{
1111
filename: '[name].[contenthash].js', // Use contenthash for better caching
12+
publicPath: '/container/latest/' // Set public path for production
1213
},
1314
plugins:[
1415
new ModuleFederationPlugin({

0 commit comments

Comments
 (0)