[{"data":1,"prerenderedAt":89},["ShallowReactive",2],{"pattern-lambda-web-pr-previews-nodejs-sam":3,"pattern-group-lambda-web-pr-previews-nodejs-sam":6},{"id":4,"title":5,"architectureURL":6,"cleanup":7,"contributors":11,"deploy":13,"description":18,"extension":19,"framework":20,"gitHub":21,"highlight":6,"introBox":25,"language":32,"level":33,"meta":34,"patternArch":35,"patternGroup":69,"patternGroupLabel":6,"resources":70,"stem":84,"testing":85,"videoId":6,"__hash__":88},"patterns\u002Fpatterns\u002Flambda-web-pr-previews-nodejs-sam.json","A preview URL for every pull request with AWS Lambda Web Functions",null,{"text":8},[9,10],"Delete the Web Function and empty the code bucket: \u003Ccode>AWS_REGION=us-east-1 scripts\u002Fdeploy.sh destroy\u003C\u002Fcode>.","Delete the stack: \u003Ccode>sam delete --stack-name lambda-web-pr-previews --region us-east-1 --no-prompts\u003C\u002Fcode>.",[12],"content\u002Fcontributors\u002Fmanish-s.json",{"text":14},[15,16,17],"Get your repository's OIDC subject prefix with \u003Ccode>gh api repos\u002Fmy-org\u002Fmy-repo\u002Factions\u002Foidc\u002Fcustomization\u002Fsub --jq .sub_claim_prefix\u003C\u002Fcode>.","Deploy the stack: \u003Ccode>sam deploy --stack-name lambda-web-pr-previews --region us-east-1 --capabilities CAPABILITY_IAM --parameter-overrides GitHubSubjectPrefix=&lt;prefix&gt;\u003C\u002Fcode>.","Deploy production: \u003Ccode>AWS_REGION=us-east-1 scripts\u002Fdeploy.sh production\u003C\u002Fcode>. Then copy \u003Ccode>src\u003C\u002Fcode>, \u003Ccode>scripts\u003C\u002Fcode> and \u003Ccode>.github\u003C\u002Fcode> into your repository and set the repository variables described in the GitHub repo.","Give every GitHub pull request its own live preview URL on a Lambda Web Function endpoint, updated on each push and deleted on close.","json","AWS SAM",{"template":22},{"patternPath":23,"templateFile":24},"lambda-web-pr-previews\u002Fnodejs\u002Fsam","template.yaml",{"headline":26,"text":27},"How it works",[28,29,30,31],"This pattern gives every pull request in a GitHub repository its own live preview URL, the way hosting platforms such as Vercel and Netlify do, using one AWS Lambda Web Function. A GitHub Actions workflow deploys each pull request to an endpoint named `pr-\u003Cnumber>`, comments the URL on the pull request, updates the same URL on every push and deletes the endpoint when the pull request closes. Merging to `main` deploys the `prod` endpoint.","A Web Function can have up to 10 endpoints, each with its own HTTPS domain, and an endpoint with `Disabled` auto-deployment keeps serving the revision that you point it at. Every endpoint in this pattern uses `Disabled`: with the default `LatestRevision`, production would serve the code of the last pull request that was pushed.","The workflows assume AWS IAM roles with GitHub OpenID Connect, so the repository stores no AWS keys. Because each endpoint has its own ARN, the preview role can change only `pr-*` endpoints and can pass only a separate preview execution role, so pull request code cannot touch the production endpoint or run with production permissions. The preview role cannot delete revisions either: the `Production` workflow deletes the preview revisions that no endpoint routes to.","Idle previews scale to zero, and each preview endpoint is capped at 2 execution environments and 100 requests per second. Preview endpoints are public HTTPS URLs like production, so add authentication in the app if previews must stay private.","Node.js","300",{},{"icon1":36,"icon2":41,"icon3":45,"icon4":49,"icon5":53,"line1":56,"line2":60,"line3":63,"line4":66},{"x":37,"y":38,"service":39,"label":40},10,45,"icon-internet","GitHub\nActions",{"x":42,"y":38,"service":43,"label":44},35,"s3","Amazon S3\nCode bucket",{"x":46,"y":38,"service":47,"label":48},61,"lambda-web-functions","AWS Lambda\nWeb Function",{"x":50,"y":51,"service":39,"label":52},88,20,"Client",{"x":50,"y":54,"service":39,"label":55},68,"Reviewer",{"from":57,"to":58,"label":59},"icon1","icon2","Upload",{"from":58,"to":61,"label":62},"icon3","Revision",{"from":61,"to":64,"label":65},"icon4","prod",{"from":61,"to":67,"label":68},"icon5","pr-N","lambda-web-pr-previews",{"bullets":71},[72,75,78,81],{"text":73,"link":74},"Deployment patterns for Lambda Web Functions","https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Fweb-functions-deployment.html",{"text":76,"link":77},"Lambda Web Function endpoints","https:\u002F\u002Fdocs.aws.amazon.com\u002Flambda\u002Flatest\u002Fdg\u002Fweb-functions-endpoints.html",{"text":79,"link":80},"Configuring OpenID Connect in Amazon Web Services for GitHub Actions","https:\u002F\u002Fdocs.github.com\u002Fen\u002Factions\u002Fhow-tos\u002Fsecure-your-work\u002Fsecurity-harden-deployments\u002Foidc-in-aws",{"text":82,"link":83},"GitHub OIDC immutable subject claims","https:\u002F\u002Fdocs.github.com\u002Fen\u002Factions\u002Freference\u002Fsecurity\u002Foidc#immutable-subject-claims","patterns\u002Flambda-web-pr-previews-nodejs-sam",{"text":86},[87],"Create a preview from your terminal with \u003Ccode>AWS_REGION=us-east-1 scripts\u002Fdeploy.sh preview 1\u003C\u002Fcode>, or open a pull request in your repository. See the GitHub repo for detailed testing instructions.","WU01KO-tAJmBVaFDYjDWic9OCEsNti6W7YqYuh4VW8w",1795189154130]