Multiple Aws Amplify preview build on single repo? - amazon-web-services

I got a nextjs app that servers the main app and the story book which i want to deployed on AWS amplify.
When i try to deploy the app having two specs in amplify.yaml it doesn't work.
amplify.yaml
version: 1
frontend:
phases:
preBuild:
commands:
- nvm install
- nvm use
- yarn install --immutable
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- "**/*"
cache:
paths:
- node_modules/**/*
storybook:
phases:
preBuild:
commands:
- nvm install
- nvm use
- yarn install --immutable
build:
commands:
- npm run build-storybook
artifacts:
baseDirectory: storybook-static/
files:
- "**/*"
cache:
paths:
- node_modules/**/*

Related

Next js on AWS amplify, how to set Environment variables

During development, everything works, the application has .env.local file. After installing to amazon amplify, the application does not see variables, I added my keys and values in Environment variables, and I also tried to add them to the console, but then the application breaks
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- EMAIL=${EMAIL}
- EMAIL_PASS=${EMAIL_PASS}
- NEXT_PUBLIC_GOOGLE_ANALYTICS=${NEXT_PUBLIC_GOOGLE_ANALYTICS}
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*

How I can deploy a subfolder into my bucket's root path?

For my react App I use the following buildspec.yml to deploy a reast Single Page Application:
version: 0.2
phases:
pre_build:
commands:
- npm install
build:
commands:
- npm run build
cache:
paths:
- /root/.npm/**/*
artifacts:
files:
- ./build/**
I also created an s3 bucket as static website and I deploy it directly via codeploy. But the folder that is deployed is into the ./build istead of the bucket's root. Is there a way to translate the paths of the codebuild's output artifacts into the deployed paths?
The codebuild path is used as a step in a codepipeline.
In order to do that you must specify a base-directory then tell the codebuild to set everything as artifact. This would be your final buildspec.yml:
version: 0.2
phases:
pre_build:
commands:
- npm install
build:
commands:
- npm run build
cache:
paths:
- /root/.npm/**/*
artifacts:
files:
- '**/*'
base-directory: './build'
And you also can safely delete the rogue ./build folder into your s3 bucket.

NextJS with Aws Amplify deployment error

Does anyone has tried AWS-Amplify for next.js deployment? I am getting this error always that "yarn build" successful but didn't deployed and failed.
Git repo is configured with auto-deployment and YML file for aws-amplify is below.
version: 1
frontend:
phases:
preBuild:
commands:
- rm -rf node_modules
- yarn install
build:
commands:
- yarn run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Use this yaml file in your build
version: 1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- yarn install
build:
commands:
- yarn run build
artifacts:
baseDirectory: public
files:
- '**/*'
cache:
paths:
- node_modules/**/*

CodeBuild + ReactNative + Expo Web - This build image requires selecting at least one runtime version

Trying to use CodeBuild for the first time, pulling data from CodeCommit. But I'm having issues with my buildspec. This is the code I have on it so far:
version: 0.2
phases:
INSTALL:
runtime-versions:
nodejs: 10
commands:
- npm install
PRE_BUILD:
commands:
- npm install --quiet --global expo-cli
- >
if [ -f yarn.lock ]; then
yarn
elif [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then
npm ci
else
npm install
fi
BUILD:
commands:
- expo build:web
artifacts:
baseDirectory: web-build
files:
- '**/*'
name:
myname-$(date +%Y-%m-%d)
cache:
paths:
- node_modules/**/*
- $(npm root --global)/**/*
I have already added the runtime for nodejs 10, it had stopped to trigger this error, but now it kicked again. Does anyone know how to properly tweak it for React-Native web projects?
I believe the phase names are case sensitive, so change them to install, pre_build and build.

Deploy nuxt on AWS amplify console

I have an aws amplify project built on top of nuxt. I'm trying to setup CI using amplify console. My build keeps failing in deploy stage, for some reason the artifacts aren't being created or can't be found:
Here's my amplify.yml file:
version: 0.1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- npm install
build:
commands:
- npm run generate
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*
If I run npm run generate locally then my app is built and can be found in the dist folder without any problems.
did anyone manage to successfully deploy an amplify/nuxt app using the amplify console?
Thanks
Update 1
change the buildspec:
version: 0.1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run generate
artifacts:
# IMPORTANT - Please verify your build output directory
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*