I have recently start using aws cdk as a newbie. so i ran lot of commands that i had no idea about.
now i want to remove all settings like env variables i created or profiles and start from scratch. what should in un install to achieve that?
I'm not totally sure what you're trying to reset but here's a few suggestions that might help:
Remove Deployed CDK Stacks
cdk destroy stack_name
Note: You'll have to do this for every stack you've deployed. This can also be done through "CloudFormation" in the AWS dashboard in your browser.
Remove CLI Settings
As per https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-configure-files.html
To remove a setting, use an empty string as the value, or manually delete the setting in your config and credentials files in a text editor.
Example:
aws configure set cli_pager ""
Remove Profiles
Unsure if you can do this easily through the CLI but you can just manually remove them from your config files. There are only two config files and they can be found using https://docs.amazonaws.cn/en_us/cli/latest/userguide/cli-configure-profiles.html
~/.aws/credentials (Linux & Mac) or %USERPROFILE%.aws\credentials (Windows)
~/.aws/config (Linux & Mac) or %USERPROFILE%.aws\config (Windows)
If you need more specific help on how to undo something then please provide an example of what exactly you ran that you would like to undo.
I need to use now multiple cluster, currently what I did is simple put all the kubeconfig
under .kube folder and any time update the config file with the cluster which I need , e.g.
mv config cluserone
vi config
insert new kubeconfig to the config file and start working with the new cluster,
Let say inside the /Users/i033346/.kube I've all the kubeconfig file one by one.
is there a way to use them as contexts without creating a new file which contain all of them.
I try to use also kubectx however when I use:
export KUBECONFIG=/Users/i033346/.kube/trial
and
export KUBECONFIG=/Users/i033346/.kube/prod
and use kubectx I always get the last one and doenst get list of the defined contexts,any idea?
KUBECONFIG env var supports multiple files, comma-separated:
export KUBECONFIG="/Users/i033346/.kube/trial,/Users/i033346/.kube/prod"
This should be enough to see all of them in kubectx.
You can even merge all configs to 1 file:
export KUBECONFIG="/Users/i033346/.kube/trial,/Users/i033346/.kube/prod"
kubectl config view --flatten > ~/.kube/config
What I used to do in this scenario is to create multiple aliases pointing to different config files.
e.g
in your .bashrc/.zshrc
edited in your ~/.bashrc or your ~/.zshrc
alias k-cluster1="kubectl --kubeconfig /my_path/config_cluster1"
alias k-cluster2="kubectl --kubeconfig /my_path/config_cluster2"
after loading the terminal k-cluster1 get pods or k-cluster2 get pods should work
I need to change my default project (deleted the previous one). Can't find documentation for how to do this from either the console or the cli. Seems to be a pretty common requirement but ....
Navigate to the GCP Console via the url https://console.cloud.google.com/ will open the project selected during the last connection. (probably cached on your browser local storage).
For gcloud commands, you can change the default project with :
gcloud config set project PROJECT_ID
or initialize a new environment with:
gcloud init
Also note that you can create multiple configurations and then switch between them easily :
gcloud config configurations create CONFIG_NAME
gcloud config configurations activate CONFIG_NAME
How can I change the current running project to another project in GCP (Google Cloud Platform) account using cli commands other than using gcloud init manually?
gcloud projects list will list the projects running on my account. I want to change the current project to any other project from the list using a cli command.
gcloud config set project $MY_PROJECT_ID
#=>
Updated property [core/project].
You may also set the environment variable $CLOUDSDK_CORE_PROJECT.
Make sure you are authenticated with the correct account:
gcloud auth list
* account 1
account 2
Change to the project's account if not:
gcloud config set account `ACCOUNT`
Depending on the account, the project list will be different:
gcloud projects list
- project 1
- project 2...
Switch to intended project:
gcloud config set project `PROJECT ID`
You should actually use the project ID and not the name as the other answers imply.
Example:
gcloud projects list
PROJECT_ID NAME PROJECT_NUMBER
something-staging-2587 something-staging 804012817122
something-production-24 something-production 392181605736
Then:
gcloud config set project something-staging-2587
It's also the same thing when using just the --project flag with one of the commands:
gcloud --project something-staging-2587 compute ssh my_vm
If you use the name it will silently accept it but then you'll always get connection or permission issues when trying to deploy something to the project.
The selected answer doesn't help if you don't know the name of projects you have added gcloud already. My flow is to list the active projects, then switch to the one I want.
gcloud config configurations list
gcloud config configurations activate [NAME]
where [NAME] is listed from the prior command.
It could be that I'm late to answer, but this command made me learn a lot about gcloud SDK
gcloud alpha interactive
It's easier to discover by yourself that you'll need gcloud config set project my-project.
However, what I like about gcloud is tab completion, so if you configure your gcloud config with configurations (I know it sounds weird but run this command gcloud config configurations list) you can easily switch between your own projects that you usually work:
The alias that I use is:
alias gcca="gcloud config configurations activate" and it works fine with zsh gcloud plugin.
EDIT:
To configure one of configurations I usually do this
gcloud config configurations create [CUSTOM_NAME]
gcloud auth login # you can also manually set but this is for lazy one
gcloud config set project [gcp-project-id]
gcloud config set compute/zone europe-west3-c
gcloud config set compute/region europe-west3
You can use ENV variables too to configure zone/project but I like when it's configured this way so I can use tab complication between projects.
Do the following:
1 - gcloud auth list
2 - gcloud projects list
3 - gcloud config set project *projectid*
(replace project id with actual project id)
Also, if you are using more than one project and don't want to set global project every time, you can use select project flag.
For example: to connect a virtual machine, named my_vm under a project named my_project in Google Cloud Platform:
gcloud --project my_project compute ssh my_vm
This way, you can work with multiple project and change between them easily by just putting project flag. You can find much more information about other GCP flags from here.
For what its worth if you have a more than a handful of projects, which I do, use:
gcloud init
This will list all your projects and give you the option to change current project settings, add a new project configuration or switch:
Pick configuration to use:
[1] Re-initialize this configuration [esqimo-preprod] with new settings
[2] Create a new configuration
[3] Switch to and re-initialize existing configuration: [default]
[4] Switch to and re-initialize existing configuration: [project 1]
[5] Switch to and re-initialize existing configuration: [project 2]
Please enter your numeric choice:
It will always ask you to login and display options for different google accounts that you may have.
Given that I manage multiple organisations and projects this approach lets' me to simply switch between them.
I do prefer aliases, and for things that might need multiple commands, based on your project needs, I prefer functions...
Example
function switchGCPProject() {
gcloud config set project [Project Name]
// if you are using GKE use the following
gcloud config set container/cluster [Cluster Name]
// if you are using GCE use the following
gcloud config set compute/zone [Zone]
gcloud config set compute/region [region]
// if you are using GKE use the following
gcloud container clusters get-credentials [cluster name] --zone [Zone] --project [project name]
export GOOGLE_APPLICATION_CREDENTIALS=path-to-credentials.json
}
gcloud projects list
To get List of Projects.
gcloud config set project [Project-ID]
For setting default project.
You can also export your project id into variable to use in future commands which helps in avoiding typos with following.
MY_PROJECT_ID=[Project-ID]
echo $MY_PROJECT_ID
Check the available projects by running: gcloud projects list. This will give you a list of projects which you can access.
To switch between projects: gcloud config set project <project-id>.
Also, I recommend checking the active config before making any change to gcloud config. You can do so by running: gcloud config list
I'm posting this answer to give insights into multiple ways available for you to change the project on GCP. I will also explain when to use each of the following options.
Option 1: Cloud CLI - Set Project Property on Cloud SDK on CLI
Use this option, if you want to run all Cloud CLI commands on a specific project.
gcloud config set project <Project-ID>
With this, the selected project on Cloud CLI will change, and the currently selected project is highlighted in yellow.
Option 2: Cloud CLI - Set Project ID flag with most Commands
Use this command if you want to execute commands on multiple projects. Eg: create clusters in one project, and use the same configs to create on another project. Use the following flag for each command.
--project <Project-ID>
Option 3: Cloud CLI - Initialize the Configurations in CLI
This option can be used if you need separate configurations for different projects/accounts. With this, you can easily switch between configurations by using the activate command. Eg: gcloud config configurations activate <congif-name>.
gcloud init
Option 4: Open new Cloud Shell with your preferred project
This is preferred if you don't like to work with CLI commands. Press the PLUS + button for a new tab.
Next, select your preferred project.
I add aliases to the .bash_alaises to switch to a different project.
alias switch_proj1="gcloud config set project ************"
Here is a script to generate aliases :) for all projects listed.
Please update the switch_proj to unique project aliases that you can remember.
gcloud projects list | awk '{print "alias switch_proj=\"gcloud config set project " $1 "\""}'
To update your existing project to another project, you can use this command line:
gcloud projects update PROJECT_ID --name=NAME
NAME: will be the new name of your project.
Check your project by running gcloud config list
Then gcloud config set "project name"
You can try: gcloud config set project [project_id]
add this below script in ~/.bashrc and do please replace project name(projectname) with whatever the name you needed
function s() {
array=($(gcloud projects list | awk /projectname/'{print $1}'))
for i in "${!array[#]}";do printf "%s=%s\n" "$i" "${array[$i]}";done
echo -e "\nenter the number to switch project:\c"
read project
[ ${array[${project}]} ] || { echo "project not exists"; exit 2; }
printf "\n**** Running: gcloud config set project ${array[${project}]} *****\n\n"
eval "gcloud config set project ${array[${project}]}"
}
Just use the gcloud projects list to get the project you have . Get the PROJECT_ID of the poject to use
After that use gcloud set project --project=PROJECT_ID to set the project.
You can change the project using the gcloud command:
gcloud config set project <your_project_name>
gcloud config set project <PROJECT_ID>
Before setting the Gcloud project see the list of available project
gcloud projects list
then set the project using
gcloud config set project $MY_PROJECT_ID
make sure you are passing project Id (not project name as both are different)
Hi Jenkins and AWS Guru's
I already look online for any possible solutions but not getting a solution for my problem. I just issued an "eb --version" on Jenkins execute shell under a test project but getting "eb: command not found" during the execution.
Wierd thing is if I issue the same command on the Jenkins box via CLI I'm getting a good response from it. Any suggestions for the fix please? thanks in advance
Your Jenkins setup has a different path than the user you logged in with.
There are two solutions:
Add the path to the executable in the PATH environment variable. Use where eb to find the correct path. Then in Jenkins, click on
Manage Jenkins -> Configure System, Global Properties. Check Environment Variables. Set Name to PATH. Set Value to $PATH:/path/to/eb. Then restart Jenkins.
Call the eb command with its fully qualified path.
EDIT: Added steps to update path in Jenkins.
this is now fixed, need to create a properties file that was basically a copy of /var/lib/jenkins/.bash_profile file which would have the correct paths and add that in Jenkins settings. Allowing it to get the required paths. After properties file is created you need to set it on Jenkins-Configure section, Place a check on Prepare jobs environment then set the full path of the properties file (/var/lib/jenkins/environment_variables.properties) on the Properties File Path and restart Jenkins