Skip to content

React Frontend (with AWS Amplify Auth & Storage) that calls an Express API running on AWS App Runner deployed with AWS Copilot.

Notifications You must be signed in to change notification settings

siegerts/amplify-apprunner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

amplify-apprunner

React frontend (with Amplify Auth & Storage) hosted on AWS Amplify that calls an Express API running on AWS App Runner.

Both projects live in the same repo:

The user's JWT from Amplify Auth is passed with the API request and verified in the service using aws-jwt-verify.

Amplify.configure({
  ...awsExports,
  ...{
    API: {
      endpoints: [
        {
          name: "apprunner-api",
          endpoint:
            process.env.REACT_APP_APPRUNNER_API || "http://localhost:8080",
          custom_header: async () => {
            return {
              Authorization: `${(await Auth.currentSession())
                .getAccessToken()
                .getJwtToken()}`,
            };
          },
        },
      ],
    },
  },
});

The API service returns a simple "promo" message for the UI.

This pattern can be extended to access additional resources or private services via the App Runner service.

Deployment

Frontend

The frontend can be deployed using Amplify Hosting continuous CI/CD from the repository. Use the API endpoint created to populate the Environment Variable REACT_APP_APPRUNNER_API in the Amplify Hosting console for the application.

API Service

Environment Variables

Update the COGNITO_USERPOOL_ID and COGNITO_CLIENT_ID environment variables in backend/copilot/api/manifest.yml. These values should coincide with the AWS Cognito Auth resources created by Amplify, and redeploy.

variables: # Pass environment variables as key value pairs.
  # LOG_LEVEL: info
  # Add in here or in AWS Console
  COGNITO_USERPOOL_ID: <value>
  COGNITO_CLIENT_ID: <value>

AWS Copilot

Once AWS Copilot is installed:

Change into the backend directory and deploy:

cd backend

copilot deploy

Once deployed, the service will be visible in the App Runner console.

About

React Frontend (with AWS Amplify Auth & Storage) that calls an Express API running on AWS App Runner deployed with AWS Copilot.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published