Aws - Amplify Cli

Card Puncher Data Processing

About

The Amplify Command Line Interface (CLI) is a unified toolchain to create and manage your serverless infrastructure on AWS.

The Amplify CLI is useful to use for provisioning resources and managing new userpools/identity pools.

Syntax

amplify <command> <subcommand>

  init                Initializes a new project, sets up deployment resources in the cloud, and makes your project ready for Amplify.
  configure           Configures the attributes of your project for amplify-cli, such as switching front-end framework and adding/removing cloud-provider plugins.
  push                Provisions cloud resources with the latest local developments.
  publish             Executes amplify push, and then builds and publishes client-side application for hosting.
  serve               Executes amplify push, and then executes the project's start command to test run the client-side application locally.
  status              Shows the state of local resources not yet pushed to the cloud (Create/Update/Delete).
  delete              Deletes all of the resources tied to the project from the cloud.
  <category> add      Adds a resource for an Amplify category in your local backend
  <category> update   Update resource for an Amplify category in your local backend.
  <category> push     Provisions all cloud resources in a category with the latest local developments.
  <category> remove   Removes a resource for an Amplify category in your local backend.
  <category>          Displays subcommands of the specified Amplify category.
  codegen             Generates GraphQL statements(queries, mutations and subscriptions) and type annotations.
  env                 Displays and manages environment related information for your Amplify project.

| Category      |
| ------------- |
| analytics     |
| api           |
| auth          |
| function      |
| hosting       |
| interactions  |
| notifications |
| storage       |
| xr            |

Management

Installation / Configuration

  • Add package
yarn global add @aws-amplify/cli
  • Configure - Once the Amplify Cli has been configured, it can access your AWS resources. It performs the same than cli configure and will create/overwrite the following files if you choose default as profile:
    • ~/.aws/config
    • ~/.aws/credential
amplify configure
Follow these steps to set up access to your AWS account:

Sign in to your AWS administrator account:
https://console.aws.amazon.com/
Press Enter to continue

Specify the AWS Region
? region:  eu-central-1
Specify the username of the new IAM user:
? user name:  myUserName
Complete the user creation using the AWS console
https://console.aws.amazon.com/iam/home?region=undefined#/users$new?step=final&accessKey&userNames=myUserName&permissionType=policies&policies=arn:aws:iam::aws:policy%2FAdministratorAccess
Press Enter to continue

Enter the access key of the newly created user:
? accessKeyId:  **********
? secretAccessKey:  ********************
This would update/create the AWS Profile in your local machine
? Profile Name:  amplifyprofile

Successfully set up the new user.

Init

An init will create a cloudformation stack (called root stack) (AWS::CloudFormation::Stack) ( a nested stack)

  • a s3 bucket (AWS::S3::Bucket) - it's a deployment bucket, to support this provider’s workflow
  • two IAM role (AWS::IAM::Role) - UnauthRole and AuthRole
    • an IAM role for unauthenticated users
    • an IAM role for authenticated users

Files:

  • The root stack’s template can be found in this folder: amplify/backend/awscloudformation
  • Provider logs the information of the root stack and the resources into the project metadata file amplify/backend/amplify-meta.json
cd appRoot
amplify init
  • Filling information
Note: It is recommended to run this command from the root of your app directory
? Enter a name for the project Bytle Site
? Enter a name for the environment bytledev
? Choose your default editor: IDEA 14 CE
? Choose the type of app that you're building javascript
Please tell us about your project
? What javascript framework are you using react
? Source Directory Path:  pages
? Distribution Directory Path: build
? Build Command:  npm.cmd run-script build
? Start Command: npm.cmd run-script start
Using default provider  awscloudformation

For more information on AWS Profiles, see:
https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html

? Do you want to use an AWS profile? Yes
? Please choose the profile you want to use default

  • Creating
\ Initializing project in the cloud...

CREATE_IN_PROGRESS bytlesite-bytledev-20190507215141 AWS::CloudFormation::Stack Tue May 07 2019 21:51:41 GMT+0200 (W. Europe Daylight Time) User Initiated
CREATE_IN_PROGRESS DeploymentBucket                  AWS::S3::Bucket            Tue May 07 2019 21:51:46 GMT+0200 (W. Europe Daylight Time)
CREATE_IN_PROGRESS UnauthRole                        AWS::IAM::Role             Tue May 07 2019 21:51:46 GMT+0200 (W. Europe Daylight Time)
CREATE_IN_PROGRESS AuthRole                          AWS::IAM::Role             Tue May 07 2019 21:51:47 GMT+0200 (W. Europe Daylight Time)
\ Initializing project in the cloud...

CREATE_IN_PROGRESS UnauthRole AWS::IAM::Role Tue May 07 2019 21:51:47 GMT+0200 (W. Europe Daylight Time) Resource creation Initiated
/ Initializing project in the cloud...

CREATE_IN_PROGRESS DeploymentBucket AWS::S3::Bucket Tue May 07 2019 21:51:47 GMT+0200 (W. Europe Daylight Time) Resource creation Initiated
CREATE_IN_PROGRESS AuthRole         AWS::IAM::Role  Tue May 07 2019 21:51:47 GMT+0200 (W. Europe Daylight Time) Resource creation Initiated
\ Initializing project in the cloud...

CREATE_COMPLETE UnauthRole AWS::IAM::Role Tue May 07 2019 21:52:05 GMT+0200 (W. Europe Daylight Time)
CREATE_COMPLETE AuthRole   AWS::IAM::Role Tue May 07 2019 21:52:05 GMT+0200 (W. Europe Daylight Time)
- Initializing project in the cloud...

CREATE_COMPLETE DeploymentBucket                  AWS::S3::Bucket            Tue May 07 2019 21:52:08 GMT+0200 (W. Europe Daylight Time)
CREATE_COMPLETE bytlesite-bytledev-20190507215141 AWS::CloudFormation::Stack Tue May 07 2019 21:52:11 GMT+0200 (W. Europe Daylight Time)
√ Successfully created initial AWS cloud resources for deployments.
√ Initialized provider successfully.
Initialized your environment successfully.

Your project has been successfully initialized and connected to the cloud!

Some next steps:
"amplify status" will show you what you've added already and if it's locally configured or deployed
"amplify <category> add" will allow you to add features like user login or a backend API
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud

Pro tip:
Try "amplify add api" to create a backend API and then "amplify publish" to deploy everything

Documentation / Reference





Discover More
Card Puncher Data Processing
Amplify - aws-export

The aws_exports.js file would be in the directory which you specified as your “Source Directory Path” when you ran an amplify init...
Card Puncher Data Processing
Aws - Amplify

The Amplify Framework provides: a set of libraries (js, ios, android) to access AWS resources UI components (for React, React Native, Angular, Ionic and Vue), a command line interface to build...
Card Puncher Data Processing
Cognito - Amplify Auth Component

Auth is a sub-component (called a category) of the amplify library and is a wrapper around amazon-cognito-identity-js All methods are available in the Auth...



Share this page:
Follow us:
Task Runner