Generate client-side configuration files for the AWS Amplify library based on your deployed Serverless backend
Install the plugin via Yarn (recommended)
yarn add aws-amplify-serverless-plugin
or via NPM
npm install --save aws-amplify-serverless-plugin
serverless.yml file to include something like the following:
Each entry in the
amplify section must consist of two parts, with two optional parts:
filenameis where you want the file to be stored. The directory must already exist.
type is one of the following:
schema.json(the AWS AppSync schema in JSON format),
graphql(a sample GraphQL operations file for codegen),
appsync(generated code for AppSync - the format is based on the extension)
appClientis the name of the Amazon Cognito user pool app client configured within the
resourcessection of the
serverless.ymlfile. It is optional.
s3bucketis the name of the S3 Bucket used for the S3 transfer utility. It is optional. If
disabled, no S3 bucket information is written to the configuration file. If not included, the first non-deployed S3 bucket will be used.
appsync type, the extension of the file is checked. Supported formats include
ts (for TypeScript),
example directory for a complete sample of an AWS AppSync client deployment with Amazon Cognito user pools.
Let's say you had four directories in your GitHub repository - one for the backend, one for your Android app in
android, one for your iOS app in
ios and one for your web resources in
web, you could add the following to the
To deploy your backend and build all the clients, you might do the following:
$ (cd backend && sls deploy -v) $ (cd android && ./gradlew build) $ (cd ios && ./build) $ (cd web && npm run deploy)
Once the deployment of the backend is done, the AWS configuration files needed for each of the builds will be updated.
Note: If you are generating a configuration file for an iOS build, ensure you do not "copy" the
awsconfiguration.json file. If you do, it will not be updated when the deployment happens.
When you are configuring AWS AppSync for Android apps, you need three files. In general, these will be as follows:
plugins: - aws-amplify-serverless-plugin custom: amplify: - filename: ../android/app/src/main/res/raw/awsconfiguration.json type: native appClient: AndroidUserPoolClient - filename: ../android/app/src/main/graphql/schema.json type: schema.json - filename: ../android/app/src/main/graphql/operations.graphql type: graphql
When you are configuring AWS AppSync for iOS apps, you need two files. In general, these will be as follows:
plugins: - aws-amplify-serverless-plugin custom: amplify: - filename: ../ios/awsconfiguration.json type: native appClient: iOSUserPoolClient - filename: ../ios/GraphQLAPI.swift type: appsync
Add both files to your XCode project. When prompted, uncheck the Copy Items box. The plugin will maintain these files for you. If you check the Copy Items box, then your project may not receive the updates if copied. If you uncheck the box, these files will be updated whenever you deploy your resources.
The following resources are supported:
resourcesor the serverless-appsync-plugin).
Amazon Cognito federated identities.
Check out the issues tab at the top of the page!
Latest commit b2f54ec on Sep 24, 2017