Amplify-cli: auth category ignored in headless amplify init/configure project

Created on 6 Aug 2019  Â·  10Comments  Â·  Source: aws-amplify/amplify-cli

Note: If your question is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum

* Which Category is your question related to? *
CI / Headless
* What AWS Services are you utilizing? *
Amplify CLI
* Provide additional details e.g. code snippets *
I'm attempting to use the headless feature of amplify CLI to pass parameters to amplify init/configure project (I've tried both). According to the best documentation I've been able to find, this code should initialize my project and add the auth category. Initialization appears to be successful, but the auth doesn't get added (or even attempted from what I can tell). When run, I receive no errors. I have tried different syntaxes for the AUTHCONFIG section, especially surrounding the empty array, but even in the scenarios where I've received no errors (and there have been a few), the auth never gets added. Am I misusing the --categories flag here?? See below code:

#!/bin/bash
cd /home/ec2-user/environment/photo-albums

set -e
IFS='|'

AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\"\
}"

AMPLIFY="{\
\"projectName\":\"photo-albums\",\
\"envName\":\"master\",\
\"defaultEditor\":\"none\"\
}"

REACTCONFIG="{\
\"SourceDir\":\"src\",\
\"DistributionDir\":\"build\",\
\"BuildCommand\":\"npm run-script build\",\
\"StartCommand\":\"npm run-script start\"\
}"

FRONTEND="{\
\"frontend\":\"javascript\",\
\"framework\":\"react\",\
\"config\":$REACTCONFIG\
}"

PROVIDERS="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"

AUTHCONFIG="{\
\"useDefault\":\"default\",\
\"usernameAttributes\":\"username\",\
\"additionalQuestions\":"[]"\
}"

CATEGORIES="{\
\"auth\":$AUTHCONFIG\
}"

amplify init \
--amplify $AMPLIFY \
--frontend $FRONTEND \
--providers $PROVIDERS \
--categories $CATEGORIES \
--yes

auth pending-response question

All 10 comments

@Joespower Do you have auth already added to your project? What does you amplify/backend/backend-config.json file look like?

@kaustavghosh06 no, I started with a clean project. When I cat the file I get the below output:

Admin:~/environment/photo-albums (master) $ cat amplify/backend/backend-config.json                                                                            
{}Admin:~/environment/photo-albums (master) $ 

This is after several attempts to get this to work, and running amplify delete after.

@Joespower You would need to add auth using amplify add auth command and then use the script mentioned above for CI/CD. There is no way to add auth in a headless moth currently. Curious to know where you read about the following configs:

AUTHCONFIG="{\
\"useDefault\":\"default\",\
\"usernameAttributes\":\"username\",\
\"additionalQuestions\":"[]"\
}"

I'm confused. I must not understand the use case for headless. I based my bash code on sample code that is specifically called out in the documentation here. Also, the sample code is here. I wanted a different outcome for authentication than what the example code gave, so I searched for documentation on what to use and found none. I ended up basing what I chose on:

supported-services.json
-AND-
string-maps.js

...Using the prompts for the auth stuff to locate a key and the mappings to identify a value that should work. Could you maybe elaborate on what you mean by your statement? Essentially, my end goal is to have an automated (scripted) test deployment based on the parameters that drive my project. I thought that's what this was for...

@Joespower So the script out here would be to create a new env and passing in params which the auth category would need if auth is already added via the CLI (this information is env specific and based off the amplify/backend/team-provider-info.json file.

I have the same problem: my amplify/backend/backend-config.json file is empty when I use amplify init --categories. When I use amplify add auth, I do get stuff added to amplify/backend/backend-config.json.

FWIW, this functionality was added in #465, but the attributes set by @Joespower are not tested by the test.

Burning way too much time on this. Various git issues ranging back years. Clearly stated in the doc and in the samples that it should work. No fixes, workarounds or even a clear admission of a bug. Disappointing.

@jmcgeheeiv @bwalsh There isn't a headless way of adding the auth category as of today and none of our docs state that way. The headless commands are currently just used in CI/CD enviornments for initing a new env based of an existing environment and pushing resources initialized using the CLI to the cloud. @bwalsh What are you trying to achieve?

Handoff to corporate devops so that they can reliably create amplify
instances.

On Sat, May 16, 2020 at 9:55 AM Kaustav Ghosh notifications@github.com
wrote:

@jmcgeheeiv https://github.com/jmcgeheeiv @bwalsh
https://github.com/bwalsh There isn't a headless way of adding the auth
category as of today and none of our docs state that way. The headless
commands are currently just used in CI/CD enviornments for initing a new
env based of an existing environment and pushing resources initialized
using the CLI to the cloud. @bwalsh https://github.com/bwalsh What are
you trying to achieve?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/aws-amplify/amplify-cli/issues/1979#issuecomment-629675345,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAALVQCETV5KXPXKHO26YDTRR3AOLANCNFSM4IJZ3I4Q
.

@kaustavghosh06, thank you for your support.

@bwalsh, like you I found a non-interactive build very useful while iterating to find find the right versions of node, angular, amplify, etc.

Then, once things started to come up, I committed my Angular/Amplify project to Git and began to use the Team environment workflow, beginning with:

amplify init --app gitURL

This does stuff like amplify add auth and amplify add storage completely automatically. The Team environment workflow seems much more solid and well-used. Importantly, it gets you the infrastructure-as-code that your corporate DevOps team needs.

However, I could not use --providers to specify the Amplify administrator profile:

yes "" | amplify init --app gitURL --providers '{...}'   # Uses the default administrator profile

so it is still not possible to specify the Amplify administrator profile without human intervention (headless). But it is still quite an improvement.

As a workaround, you could:

  • Name your Amplify administrator account default (rather odious). On the other hand, maybe it is is better for amplify init to never use an administrator profile, so that you do not accidentally publish to production.
  • Perhaps commit amplify/.config/local-aws-info.json to Git, contrary to .gitignore. I have not tried this yet. I can see how it will cause trouble for developers who do not have the Amplify administrator profile defined, or would prefer that the Amplify administrator profile be used only explicitly.

Regarding the above yes "" | amplify init ... trick, see #4242.

Was this page helpful?
0 / 5 - 0 ratings