Overview

I used AWS CDK to create a static site with CloudFront + S3. Additionally, I used CloudFront Functions to add Basic authentication and processing to append index.html to requests that do not include a filename or extension in the URL. I also added a custom domain, so this is a memo of the process.

While somewhat incomplete, the source code is available in the following repository.

https://github.com/nakamura196/staticBasic

The intended use is to prepare an .env file like the following and run cdk deploy.

CRBRADEEUECORCCGCMTOKIOA_REOUIADTNNNR__=T_NNNu=N=AAsyAaMM-yMrEEeyEn==ay=:aasbaaatbwaa-bs..1.:bbcabbocbbmm..:ccxooxmmxx

The explanation for each item is as follows.

ItemDescriptionExample
CERT_ARNCertificate ARNarn:aws:acm:xxxx
RECORD_NAMEDomain name to configureaaa.bbb.com
BUCKET_NAMES3 bucket name for file storageaaa.bbb.com
REGIONRegion nameus-east-1
ACCOUNTAWS account number (12-digit number)123456789012
DOMAIN_NAMEHosted zone namebbb.com

Stack

The following Stack was created.

i}iiiiiiiide}mmmmmmmmmoxpSSRaaafpppppppptpc}ottewwwrooooooooeooraamsssorrrrrrrrnrnsccccc}c}c)c}wc}c)c}n}tcco___mttttttttvtsuooooo)o)o;o)eo)o;o)e)kkvcci.tpnnnnnd;nrab;nt"{}naep]r;bnc};nt"cndccdd}p;wrzt);{,Palla"{{ccresssssoSseuuCshOSscfr,esCso)shCeCsoeoee,rRea,rloomaolurtttttm3tmtcltirc3ttfin)siltdf,tierltmrmffaccvo}f]iorcnrnoPuu,wCaaaaaCanac(aookosioiene,otoeisrtoatmaalaair)u,cuooegepoddsosssssesfstsrdbchiwvDeuo,gmwoccwoueuc:lc,tudiieuulcceaio,n{}etur:ewslff-nrisoceoueoneaetdrimentirrBdfeeidinfnllohhwwgrc,Cetdt,irrcssicrttdgrocmcrsNbllNFinebs:paicuFFaPrfFsNitttweeesiitfel5eNh:tcoodt3aloaio(S(poaktItasPeargAnS:awgecruwatirtac:RBedPr_ngiuva35aoaynnkrmourft)tserieDemiotmoictiilsiskonsticormaoedMoPc:iones3msrr,tt-ufutgie;ac,dnt=detleennc:t[as_n:enc_hfaniet`ohMelrlnncns.eItog,_lcrfdeecntoNNNZ,eiO,tAee"m:iAtttc:ittbse$taetioonAAtt:A,Deueoitorf5tavipiaaapoBcbcs`Bs.ac[.ilceu:,{OvthctuecsiTRdttrbmor3stcedmmmrnuyjcs$u3E[mc`aFoo"a"tbbihoyodwcsoyaeZesi"}moefB:,eeeoec:eOeI{c:f.e$dunuat,i[ujood:cfeonpwco5.g;"nffracIkcrsdbkGfCs{dndseorcerdsorasc:eson3Cifa"trr}osCp===edeRtiseueeeaswTc=fsnekc:s:alowsi:_re.lnrwaoomiorstesgIncttcnIeotre=cet:wPnsIaccdIRososwfmmfcnoppps=m:idtkPOtodbRinot=ot:{asot_dtfal(deu,m-srr"Ssprrr.=oneieob.neseoensCrNaw_l.ceiFwot,cdc-o""odttsoooervtnttljAinisnwtenda"wsciVlnousuhoF"dcmaamoar)cccnonarAtyNieLctto.rreNmis_lciotnn_dirrckdwwtcu;eeevueluci"accLaieuaFetwaen_coyeuisccfsdoo-k"ss"ekcsss.twPect,mytOltBrwudim}dclu:wdt:tlr,Tnnl-a--antsssCeo,eyeS"WUyucsnifae-elodefyiooatsilwccwve,...E5sls}t],s.ce_criwcxoufrr,[oun"rTtbisdds"xeeeR33is=-a,eckPctecs]l.udrPondtRgar/b-kk-;tinnnT..citrleolica_,ohdforn,f.oerua/c--cedvvv_HByIndePotloottcutfrnotrPutgcwadlldn:...Aou.deemru.iun.eldmrott_ort.etswkiikdRDBRscDewneidbcdCj.oflon.ooniefts-s-bb-ssEOUNtkEntnnFuyfosfur"ntCcrtc5r("s-l//ltCMCeeStcitcrc(rd"rdo,t.aoi.e3od;3iiaaiSrOAKdtTiltiokwoe,ofn.CclgFCRmi"abwwbtiRIEZ(Rtoy=pneen.mrtAahPiuleAs;m/ss/anDNTotOyu`attbtfCo`lceonnaclt"a--acg___"nhYd,nlOAS.ren,lhPlscsoir;wrrwk,NNN"ei,fe(rriFortoeoi.tsraisoosAAA;.srwintumt.wdlcSi.dsb-uu-{pMMMf,og}enFiDeMiy3oPS(ucttcrEEErnii/Bcifidec.OnRetleeeoo"tan*utlisMtyRrEItio55rpmW.mA`ciecteh.EivC"ou33tsLeO.c]ko(artoCDgeE,nd"-i?obrPc,en{tihdAIin_)f;tf:"""osioet(ebosCRntC{rai"""kiglsPtAud.HE(TLorcS;;;utiisohrtsCICwyAngatpencIlini.ANTepSteta(BAydis(oACG_beS"tectucSec,nLH_Ts._;smkhcctny(LEOOiVA"aPikeatS"tO_P_tIL;nrsestitChWGTHeELao,tsetali_EITBW,gp"ImytosGTMTuEes",deSeu,E_IPcRr)Hen3mdTHZSk_"o{ntCeF"_EE,eR;{st(anrdHADtEti{ntoiED,,Qeto)nsA,Udyn;ttD{EZ(iFr,SocuiTnanb,elcuIUttdsii"eoo,rnnI""{d,,{{

Summary

There may be some areas where consideration was insufficient, but I was able to experience the convenience of AWS CDK. We hope some parts of this serve as a reference for others.