{"id":984,"date":"2022-12-07T21:29:58","date_gmt":"2022-12-07T21:29:58","guid":{"rendered":"http:\/\/oqtacore-blog-473533498.us-east-1.elb.amazonaws.com\/?p=984"},"modified":"2023-01-18T10:42:57","modified_gmt":"2023-01-18T10:42:57","slug":"fixing-a-failing-monorepo-build-on-the-new-aws-amplify","status":"publish","type":"post","link":"https:\/\/oqtacore.com\/blog\/fixing-a-failing-monorepo-build-on-the-new-aws-amplify\/","title":{"rendered":"Fixing a failing monorepo build on the new AWS Amplify&#8217;s Web Compute platform"},"content":{"rendered":"<p>AWS Amplify has recently introduced a new platform called &#8220;Web Compute&#8221; that claims better support and performance for Next.js 12 and higher. But for us, it proved to be a disaster.<\/p>\n<p><!--more-->We have migrated to it and our website went down, and we spent many hours trying to get things working back again. If you have been using AWS Amplify for the last few years, you probably have the same problem as we do. The build completes, but then the website does not work.<\/p>\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_did_it_happen\"><\/span>How did it happen?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Long story short, AWS has moved to the new platform called &#8220;Web Compute&#8221;. It is opposed to the old platform &#8220;Web Dynamic&#8221; that probably did not have a name just a few months ago.<\/p>\n<p>It is possible that either you created a new Amplify app, or just migrated the old one<\/p>\n<div id=\"attachment_985\" style=\"width: 738px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-985\" class=\"wp-image-985\" src=\"http:\/\/blog.oqtacore.com\/wp-content\/uploads\/2022\/12\/2022-12-07_20-24-11-2.png\" alt=\"A button to migrate AWS Amplify to Web Compute\" width=\"728\" height=\"331\" srcset=\"https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-24-11-2.png 1020w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-24-11-2-300x136.png 300w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-24-11-2-768x349.png 768w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-24-11-2-180x82.png 180w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-24-11-2-800x364.png 800w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><p id=\"caption-attachment-985\" class=\"wp-caption-text\">A button to migrate AWS Amplify to Web Compute<\/p><\/div>\n<p>&nbsp;<\/p>\n<div id=\"attachment_986\" style=\"width: 731px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-986\" class=\" wp-image-986\" src=\"http:\/\/blog.oqtacore.com\/wp-content\/uploads\/2022\/12\/2022-12-07_20-22-13.png\" alt=\"Popup when migrating an AWS Amplify app from Web Dynamic to Web Compute\" width=\"721\" height=\"440\" srcset=\"https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-22-13.png 814w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-22-13-300x183.png 300w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-22-13-768x469.png 768w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-22-13-180x110.png 180w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-22-13-800x488.png 800w\" sizes=\"auto, (max-width: 721px) 100vw, 721px\" \/><p id=\"caption-attachment-986\" class=\"wp-caption-text\">Popup when migrating an AWS Amplify app from Web Dynamic to Web Compute<\/p><\/div>\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"The_problem\"><\/span>The problem<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The build succeeds<\/p>\n<div id=\"attachment_987\" style=\"width: 347px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-987\" class=\"size-full wp-image-987\" src=\"http:\/\/blog.oqtacore.com\/wp-content\/uploads\/2022\/12\/2022-12-07_20-29-35.png\" alt=\"AWS Amplify successful build and deploy\" width=\"337\" height=\"113\" srcset=\"https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-29-35.png 337w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-29-35-300x101.png 300w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-29-35-180x60.png 180w\" sizes=\"auto, (max-width: 337px) 100vw, 337px\" \/><p id=\"caption-attachment-987\" class=\"wp-caption-text\">AWS Amplify successful build and deploy<\/p><\/div>\n<p>but then it fails when rendering the page:<\/p>\n<div id=\"attachment_988\" style=\"width: 922px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-988\" class=\"size-full wp-image-988\" src=\"http:\/\/blog.oqtacore.com\/wp-content\/uploads\/2022\/12\/2022-12-07_20-28-45.png\" alt=\"503 ERROR The request could not be satisfied. The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions. \" width=\"912\" height=\"293\" srcset=\"https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-28-45.png 912w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-28-45-300x96.png 300w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-28-45-768x247.png 768w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-28-45-180x58.png 180w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-28-45-800x257.png 800w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><p id=\"caption-attachment-988\" class=\"wp-caption-text\">The Lambda function associated with the CloudFront distribution is invalid or doesn&#8217;t have the required permissions.<\/p><\/div>\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Whats_the_reason_of_the_failure\"><\/span>What&#8217;s the reason of the failure?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The underlying reason of the failure is that the build process changed, and if your monorepo build has various manual steps with different paths in <strong>amplify.yml<\/strong>, some files will not get into the package. You can just compare the lambdas generated bu the old build and the new build<\/p>\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Simple_solution\"><\/span>Simple solution<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you don&#8217;t have time to fix the build, you can create the old-fashioned Web Dynamic app. It will work just as it has worked before. The important thing here &#8211; IT can only be done via the AWS CLI or other API client.<\/p>\n<p>Here is my solution:<\/p>\n<ol>\n<li>Create (or get already existing) <a href=\"https:\/\/docs.aws.amazon.com\/powershell\/latest\/userguide\/pstools-appendix-sign-up.html\" target=\"_blank\" rel=\"noopener\">security credentials for an AWS user<\/a> with sufficient permissions. Remember the <strong>Access key ID<\/strong> and <strong>Secret Key<\/strong><\/li>\n<li>Create (or find an already existing) role to be used with Amplify. The easiest would be to get a service role from an already existing Amplify app. You need the ARN of this role, remember it as %ROLE_ARN%<\/li>\n<li>Get the repository URL that you want to use. Do not include `\/tree\/main` (opposed to what you see in the AWS Amplify&#8217;s UI). Remember the repo URL as %REPO_URL%. Also remember the branch that you want to use as %BRANCH%<\/li>\n<li>This one is tricky. I will suppose that you use github, so you will need to create an access token for github. The best part is, AWS Amplify will replace it with its own token as soon as you are done, but you will still need to create one first.\n<ul style=\"list-style-type: disc;\">\n<li>Visit <a href=\"https:\/\/github.com\/settings\/tokens\/new\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/settings\/tokens\/new<\/a>. I am using the classic here as it&#8217;s not important.\n<ul style=\"list-style-type: circle;\">\n<li>Add a name, then select all &#8220;repo&#8221; permissions<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-989\" src=\"http:\/\/blog.oqtacore.com\/wp-content\/uploads\/2022\/12\/2022-12-07_20-48-27.png\" alt=\"Repo permissions on github\" width=\"794\" height=\"236\" srcset=\"https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-48-27.png 794w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-48-27-300x89.png 300w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-48-27-768x228.png 768w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-48-27-180x54.png 180w\" sizes=\"auto, (max-width: 794px) 100vw, 794px\" \/><\/li>\n<li>Create the token by pressing &#8220;Generate the token&#8221; in the bottom<\/li>\n<li>Here is your access token, make sure to remember it as %ACCESS_TOKEN%<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-990\" src=\"http:\/\/blog.oqtacore.com\/wp-content\/uploads\/2022\/12\/2022-12-07_20-50-39.png\" alt=\"github personal access oken\" width=\"668\" height=\"207\" srcset=\"https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-50-39.png 804w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-50-39-300x93.png 300w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-50-39-768x238.png 768w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-50-39-180x56.png 180w, https:\/\/oqtacore.com\/blog\/wp-content\/uploads\/2022\/12\/2022-12-07_20-50-39-800x248.png 800w\" sizes=\"auto, (max-width: 668px) 100vw, 668px\" \/><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Install AWS CLI <a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/getting-started-install.html\" target=\"_blank\" rel=\"noopener\">https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/getting-started-install.html<\/a><\/li>\n<li>Open the console (powershell or Git Bash on Windows, terminal on MacOS and Linux)<\/li>\n<li>Run\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">aws configure<\/pre>\n<\/li>\n<li>Provide the Access key ID, Secret Key and region (the region should be the same as the Amplify app&#8217;s). Set the output format to `json`<\/li>\n<li>Replace variables in percent marks with the values that you remembered from the previous steps\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">aws amplify create-app --platform WEB_DYNAMIC --repository %REPO_URL% --name admin --access-token %ACCESS_TOKEN% --iam-service-role-arn %ROLE_ARN%<\/pre>\n<\/li>\n<li>You will get a json in your output. Remember the app id from it<\/li>\n<li>Run <strong>aws amplify create-branch &#8211;app-id %APP_ID% &#8211;branch-name %BRANCH% &#8211;stage PRODUCTION <\/strong>and replace variables in percent marks with the values that you remembered from the previous steps<\/li>\n<li>Now you can visit the AWS Amplify and work with the new app from the UI. I would recommend reconnecting the repository from the UI and removing your personal token on Github that you created during the steps.<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AWS Amplify has recently introduced a new platform called &#8220;Web Compute&#8221; that claims better support and performance for Next.js 12 and higher. But for us, it proved to be a disaster.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_mo_disable_npp":"","yasr_overall_rating":0,"yasr_post_is_review":"","yasr_auto_insert_disabled":"","yasr_review_type":"","footnotes":""},"categories":[1],"tags":[26],"class_list":["post-984","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-tech-stuff"],"acf":{"image":1097},"yasr_visitor_votes":{"number_of_votes":0,"sum_votes":0,"stars_attributes":{"read_only":false,"span_bottom":false}},"_links":{"self":[{"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/posts\/984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/comments?post=984"}],"version-history":[{"count":23,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/posts\/984\/revisions"}],"predecessor-version":[{"id":1098,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/posts\/984\/revisions\/1098"}],"wp:attachment":[{"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/media?parent=984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/categories?post=984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oqtacore.com\/blog\/wp-json\/wp\/v2\/tags?post=984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}