Feedback: Multi-environments and Team workflows feature
Summary
A new feature of the Amplify CLI has been released support multiple environments and team workflows. This feature was developed based on feedback from customers and project contributors. The feature is in BETA and will be merged into the main CLI after testing, validation, and feedback.
Details
Based on all of your feedback on the RFC – CI/CD workflows and Multiple Environments as a part of Amplify CLI GitHub issue, we’ve released a beta version of the CLI (npm install -g @aws-amplify/cli@multienv) to support multiple environments, team workflows and integrate with your CI/CD flows.
The new CLI has all of the same functionality as the previous versions but also supports a Git style workflow for switching between environments, teams, and even sharing projects. The internal structure of the CLI metadata has changed slightly though and a one-time migration of existing projects is necessary. We will soon be releasing an automatic migration feature into the build as well as a guide for manually migrating projects. Once the features are seen as well tested and stable, as well as the migration features we will merge into the main CLI. The community testing, feedback, and validation will help with this process.
When the automatic migration feature will be added, we still recommend backing up your existing local project before testing.
Please check out the detailed documentation for more information:
https://aws-amplify.github.io/docs/cli/multienv?sdk=js https://aws-amplify.github.io/docs/cli/multienv?sdk=ios https://aws-amplify.github.io/docs/cli/multienv?sdk=android
Also, as a part of our feedback mechanism, we’ve opened up this GitHub issue, to track feedback from everyone, iterate on this beta version and then merge it to master. Please leave any feedback on issues, bugs, or even successes so we can gather the feedback.
First of all: thanks for the great job that you are doing.
I started to use the new cli on an existing project. I removed all the resources from the cloud and create a new environment by following the steps described in https://aws-amplify.github.io/docs/cli/multienv?sdk=js. On the init step the cli was hanging on the message "Successfully created initial AWS cloud resources for deployments.". Only the deployment bucket + Auth/Unauth roles have been created. I had to kill the amplify init profile to quit the execution. And unfortunately when I do a amplify status it displayed that there is no resources. I cannot see the resources I defined before the migration.
Current Environment: dev
| Category | Resource name | Operation | Provider plugin |
| -------- | ------------- | --------- | --------------- |
where before the migration I had the following:
Current Environment: undefined
| Category | Resource name | Operation | Provider plugin |
| -------- | --------------- | --------- | ----------------- |
| Auth | cognito17950874 | Create | awscloudformation |
| Function | sensors | Create | awscloudformation |
| Function | gateways | Create | awscloudformation |
| Function | sensorData | Create | awscloudformation |
| Api | sensors | Create | awscloudformation |
| Api | gateways | Create | awscloudformation |
| Api | sensorData | Create | awscloudformation |
| Storage | sensors | Create | awscloudformation |
| Storage | gateways | Create | awscloudformation |
| Storage | sensorData | Create | awscloudformation |
@abdelhakim-atmani Thanks for the feedback. Which version of the CLI are you using?
When I run amplify version it returns 0.2.1-multienv.2
@abdelhakim-atmani And are you migrating your project (intitialized using an older version of the CLI), to a newer one? Can you please mention the list of steps so that we can reproduce this issue? Also, did the CLI ask you for an auto-migration?
I created the project with the old version of the cli.
I removed all the resources from AWS using the console.
I updated the cli version to the new one
I created a new branch git checkout dev
Then I initialised the project amplify init
Where it asked me if I want to migrate the project to the new version (I said yes)
Migration done successfully
It asked me if I want to use an existing environment (I said no)
I specified the name of the new environment
I choose my profile
After that it created the deployment bucket and the Auth/Unauth roles.
And now when I run amplify status the list of resources is empty.
And I have another question regarding the new cli.
In the documentation you mention a command amplify env add to add an external CFN. Is there any example on how to use it and what is it supposed to do ? I did not find any documentation.
@abdelhakim-atmani
The Current Environment: undefined step is weird. When you migrate, it should have created an env called NONE -> on an amplify migrate command. Also, I don't think the command was hanging, but it was initializing a new environment with your resources. But since you killed the process, it wasn't able to initialize your environment correctly.
The undefined step is because the first time I did not accept the auto migration. Once I did the migration it was showing NONE. Regarding the command which was hanging, I did not notice any movement from the CF console or on my laptop. I will re-run it and wait.
@abdelhakim-atmani Let me know your console logs if you error out or hang this time. Thanks
Great !!! It took more than 10 minutes but finally my environment is setup. During these 10 minutes I had only the message "Successfully created initial AWS cloud resources for deployments." displayed. I had no information about what is going on. Some logs on the console would be very cool. Thanks for your help.
Can I have more precision about the command amplify env add ?
@abdelhakim-atmani Did it take you 10 minutes to just initialize the environment or to push it? For me an avergae it takes less than 5 seconds to just initialize a new environment (excluding the pushing of all the resources) with all the categories enabled. I'm curious to know which OS you're using?
The amplify env add command is useful when you want to import a pre-existing stack/environment, initialized using the Amplify CLI, say in some other project. An example of the usage could be something like this:
#!/bin/bash
set -e
IFS='|'
AWSCLOUDFORMATIONCONFIG="{\
\"Region\": \"us-east-1\",\
\"DeploymentBucketName\": \"mytestproject67-20181106123241-deployment\",\
\"UnauthRoleName\": \"mytestproject67-20181106123241-unauthRole\",\
\"StackName\": \"mytestproject67-20181106123241\",\
\"StackId\": \"arn:aws:cloudformation:us-east-1:132393967379:stack/mytestproject67-20181106123241/1c03a3e0-e203-11e8-bea9-500c20ff1436\",\
\"AuthRoleName\": \"mytestproject67-20181106123241-authRole\",\
\"UnauthRoleArn\": \"arn:aws:iam::132393967379:role/mytestproject67-20181106123241-unauthRole\",\
\"AuthRoleArn\": \"arn:aws:iam::132393967379:role/mytestproject67-20181106123241-authRole\"\
}"
PROVIDER_CONFIG="{\
\"awscloudformation\":$AWSCLOUDFORMATIONCONFIG\
}"
AWS_CONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
\"profileName\":\"default\"\
}"
amplify env add \
--name myownv \
--config $PROVIDER_CONFIG \
--awsInfo $AWS_CONFIG \
--yes
So, in the case above, a new environment would be initialized in your current project using the configuration metadata provided as a part of the flags.
You can get this project metadata from another project using the amplify env get --name <env-name>
Thanks for the precisions.
It took me 10 minutes just to initialise.Does it need to connect to internet ? My connection was very slow yesterday. I have a mac book pro (2017) and the os version installed is 10.13.6.
Is there any plan to be able to add custom CF to the project ? I put a comment on the following issue: https://github.com/aws-amplify/amplify-cli/issues/80
Today I did a push and it is still running (more than 15 minutes). When I checked CF in the AWS console nothing is running and in my terminal I have the message: "Updating resources in the cloud. This may take a few minutes..." Any idea on how I can see what is the problem ? Is there any logs to have more details ?
AFAIK, Amplify does not currently support the following use-case:
An app where multiple front-ends share the same backend. I have an Admin webapp and a customer-facing webapp. Ideally, these two projects would live in different git repos and I would able to do "amplify pull" to retrieve updates. Multienv seems to be approaching this functionality... is it all of the way there yet?
@abdelhakim-atmani With this @multienv release you can totally share your backends between different projects. And we also have the amplify env pull command now with the @multienv support which makes it easier for the backends across multiple frontend projects to be in sync.
So here's probably what you could do. You would need to copy over your amplify directory from a project (say a JS project) to another frontend project (say android). (Note: Only copy over the files which are not present in the amplify section of your .gitignore file - I would recommend using a VCS to get this cloning process done). After you do so, run the amplify init command and select the appropriate environment you want to pull from. After this, you would want to run an amplify configure project command to tell amplify which frontend your project is using. Thats it!
To keep the backends in sync in the future, you would run an amplify env pull [--restore] to pull in the current backend configurations of the resources in the cloud for any of your environments.
Thanks @kaustavghosh06 for the precisions.
I finally found why the push was taking so much time. One step in the push process is to zip the folder ${projet}/amplify/#current-cloud-backend and to upload it in a S3 bucket.
In my case this file is huge ( > 2 GiB). The reason of that is because this folder contains node_modules of all functions and all builds (zip files).
Check the file @aws-amplify/cli/node_modules/amplify-provider-awscloudformation/lib/push-resources.js there is a function called storeCurrentCloudBackend and this function is the one which zip and upload the file in S3.
Is this step really required ? If yes does it need to include this folders/files (node_modules and all builds) ?
@kaustavghosh06
Not sure if it's on the roadmap but what about adding amplify pipeline add that would generate cloudformation templates to setup a CodePipeline like @teknogeek0 presented here?
This is great! Thanks for the new functionality.
The restrictions on environment name are quite harsh. I would like environment names that allow digits, dashes and can be longer (say up to 20 chars). This would let me create environments that match the names we use for those environments elsewhere.
This is great! Thanks for the new functionality.
The restrictions on environment name are quite harsh. I would like environment names that allow digits, dashes and can be longer (say up to 20 chars). This would let me create environments that match the names we use for those environments elsewhere.
We'd love this too (realizing we'd probably be restricted to valid S3 bucket and DNS naming conventions). Reason is we're thinking a git post-checkout hook to create a new env matching the branch name would be nice to add to our repos to make the git branching/amplify env creation flow a little easier for developers to follow
@kaustavghosh06 Per the use-case from earlier, I think that the easiest way to do it would be a separate repo for my typescript amplify code (an API package). Then, I would import the API package into my client packages (eg. admin web app, customer web app). It's nice that Amplify generates files and folders into the root dir of the project, but that becomes messy across multiple projects.
Is there a reason NOT to use amplify in a separate package/repo? Is there magic happening such that amplify needs to be located at the root of a typescript project?