You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enter Origin Domain Name, (S3 bucket name you created shown in the dropdown).
Yes, Restrict Bucket Access. Create a new Identity. Yes, Update Bucket Policy.
Change Viewer Protocol Policy (Redirect HTTP to HTTPS).
Include Lambda Auth function (Viewer Request) if you already have one, if not see the next section that will guide you how to setup a lambda function.
Input Default Root Object file example index.html
Create Distribution
Progress status shows when its finished
Linking Auth Lambda function (need IAM:CreateRole permissions)
Create function from scratch and name it.
Select runtime, default is fine.
Copy and paste the function below, change authUser & authPass.
When done link this to an already Existing role. example lnerailway-lambda. Copy the ARN at the top example arn:aws:lambda:us-east-1:986634511047:function:kopaki-simple-auth
Return to CloudFront and scroll down and select (Viewer Request)
Enter ARN and add :2 at the end example arn:aws:lambda:us-east-1:986634511047:function:kopaki-simple-auth:2
Save
'use strict';exports.handler=(event,context,callback)=>{// Get request and request headersconstrequest=event.Records[0].cf.request;constheaders=request.headers;// Configure authenticationconstauthUser='enterUsername';constauthPass='enterPassword';// Construct the Basic Auth stringconstauthString='Basic '+newBuffer(authUser+':'+authPass).toString('base64');// Require Basic authenticationif(typeofheaders.authorization=='undefined'||headers.authorization[0].value!=authString){constbody='Unauthorized';constresponse={status: '401',statusDescription: 'Unauthorized',body: body,headers: {'www-authenticate': [{key: 'WWW-Authenticate',value:'Basic'}]},};callback(null,response);}// Continue request processing if authentication passedcallback(null,request);};