I have EC2 instance, up and running good. Now I want a copy of the source code to be moved to AWS Code commit for further development and deployment.
Basically souce code should be moved from AWS EC2 to AWS Codecommit.
You need to either SSH (if Linux), or RDP (if windows), into the machine. Turn your source directories into a git repository, and then git push it to your remote (code commit) repository.
You basically do it the exact same way you would do it from any other machine - the fact that it is an EC2 instance really doesn't matter in this case.
First of all you have to create a git credential from AWS IAM. You need these credential whenever you pushed your code into codecommit. Alternatively, you can also upload your SSH public key into fAWS codecommit so that you don't need to enter your credentials every time whenever you push your code.
then follow the steps mentioned bellow:
Type git init while you are on your project folder in EC2
Then git add .
Then type git commit -m 'your custom commit message here'
Create a repo in CodeCommit from AWS Management Console.
Add then from your project folder, type remote origin by typing git remote add origin https://git-codecommit.us-east-1.amazonaws.com/v1/repos/testrepo (if you using HTTPS protocol) or git remote add origin ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/testrepo (if you are using SSH protocol)
Then push your code by typing git push origin master. in this stage, you have to enter your credentials such as AWS username and password or don't need them if you already uploaded your SSH public key into AWS code commit.
Related
I'm in the process of deploying/pushing (GitHub) a Python/Django application with Amazon RDS PostgreSQL db to AWS Elastic Beanstalk via Code Commit from PyCharm.
I uploaded my server certificate (having SSL issues, most can disregard the --no-verify-ssl):
aws iam upload-server-certificate --server-certificate-name CSC --certificate-body file://public.pem --private-key file://private.pem --no-verify-ssl
etc. Worked fine.
eb init Set-up Code Commit, SSH:
Do you wish to continue with CodeCommit? (y/N) (default is n): y
Enter Repository Name
(default is "origin"):
Successfully created repository: origin
Enter Branch Name
***** Must have at least one commit to create a new branch with CodeCommit *****
(default is "master"):
Username for 'https://github.com/mygitusername/myapp.git': user#email.com
Password for 'https://user#email.com#github.com/mygitusername/myapp.git':
Successfully created branch: master
Do you want to set up SSH for your instances?
(Y/n): y
Select a keypair.
1) mykeypairname
...
Worked fine.
eb create Setup environment, etc.
Enter Environment Name
(default is eb-myapp-dev):
Enter DNS CNAME prefix
(default is eb-myapp-dev):
Select a load balancer type
1) classic
2) application
3) network
(default is 2):
Would you like to enable Spot Fleet requests for this environment?
(y/N): n
Starting environment deployment via CodeCommit
...
Worked fine.
Then I go to PyCharm to commit changes, then push in Git, I'm asked for my Code Commit "credentials". I think, my AWS access key ID and secret key? I used/confirmed via aws configure these are accurate. Maybe but there's an option for "Password helper" so I click that. Now I'm unable to get back to that screen to enter my credentials, or at least try. I keep getting:
Push failed
Unable to access 'https://git-codecommit.us-east-1.amazonaws.com/v1/repos/origin/': The requested URL returned error: 403
How can I configure my AWS "Code Commit" credentials in PyCharm?
Original Poster, here. Here is how I resolved the problem.
Run these commands to add the AWS credential helper to ~/.gitconfig:
git config --global credential.helper '!aws codecommit credential-helper $#' credential.UseHttpPath true
git config --global credential.helper '!aws --profile CodeCommitProfile codecommit credential-helper $#'
Run git config --global --edit to verify your input.
Open Keychain. Add '+' git-codecommit.us-east-2.amazonaws.com and your Access Key ID in username and Secret Key in password. Save and close.
Delete the rule you just created in Keychain for git-codecommit.us-east-2.amazonaws.com.
Git is set to use the Keychain Access utility on macOS, which may cause problems with the Amazon Code Commit service. Change this by running the following command:
git config --system --unset credential.helper
You should get something back like, either: "no value exists" or "removed."
Finally, I followed these AWSCodeCommitPowerUser instructions: https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-gc.html#setting-up-gc-account.
I'm not sure which one of those actually fixed my problem, but after all this, I opened PyCharm and did a commit/push. Now it works.
I want to be able to work with git via my AWS Lightsails SSH terminal running on bitnami, how do I connect the terminal to bitbucket via SSH so that I can clone the repo each time I need to make a deployment. Also If there are better ways of deploying a nuxt app to aws lightsails, please share.
First create a new ssh-key and add it under .ssh/authorized_keys in your AWS Lightsail instance.
Add your created deployment key in Bitbucket. Then write a bitbucket deployment pipeline to deploy. You can find sample configs from here.
Before you choose to go this route consider that cloning a repo isn't going to make lightsail work automatically. You still have to prepare the correct entry point (domain) and then for example if you're running an express server you'd have to prepare the lightsail instance for that.
Having said that create an ssh key:
1. ssh-keygen -t ed25519 -C "your email"
2. Save to directory (you can change if you'd like):
Enter file in which to save the key (/home/bitnami/.ssh/id_ed25519)
3. Enter password or hit return for no password
4. Copy your ssh key: cat /home/bitnami/.ssh/id_ed25519.pub
5. In bitnami click your repository then you will see left hand menu. There click on Repository Settings
6. Click Access keys (left hand menu)
7. Click Add Key
8. Enter the label and paste the contents of step 4 (should be in terminal of step 4). Click Add SSH Key.
After this you should be able to clone and execute git commands. (Please make sure git is added to the server)
I've been using the AWS console to upload a WAR file for deployment. Now I want to do it from the command line. I've been following this guide and see eb init and read the help with eb init --help and eb --help, but the only option is to create a new application.
usage: eb init <application_name> [options ...]
Initializes your directory with the EB CLI. Creates the application.
positional arguments:
application_name application name
How do I link my local source project directory to an existing application in AWS console?
I would expect a command like eb link or something, like how you can just add a Git remote with Heroku and automatically link an existing project to an existing app.
When you perform eb init in the directory containing your source code, eb will prompt you for an application name and an environment name. This way you can link your source code to what ever application/environment is deployed on Beanstalk.
It worked after I got the AWS CLI keys for the project and ran aws configure. I had old keys in ~/.aws/ from a different project from perhaps a decade ago that used a different format. Once I got new keys, that were given permission for these particular apps, and ran aws configure and set the region, then eb init would present a menu of applications to choose from. The command aws elasticbeanstalk describe-applications has to work first before eb can work. I was expecting it would ask for a username and password, like Heroku does.
Install aws and eb command line tools:
Install awscli
Get keys from AWS admin devops.
aws configure (Example Region: 'us-east-1')
aws elasticbeanstalk describe-applications
Install Python
pip install awsebcli --upgrade --user
Add eb to your PATH, probably %USERPROFILE%\AppData\Roaming\Python\Python37\Scripts
eb init
eb list / eb logs / eb ssh / eb status / eb config / eb help
Beanstalk differs from Heroku in this workflow, unless you are using CodeCommit. I am assuming you are just using S3 to store your application versions.
The EBCLI command to do this is:
eb create-application-version
You can specify an application, a version label, as well as either a CodeCommit repository, a codeBuild build, or a source bundle in S3. API docs
You will need to run a separate command before create-application-version to upload to your S3 bucket.
Using the CLI:
aws s3 cp <filename> <s3bucket>
API docs
You can also use the console.
It seems like that guide skips initializing your local git repository. For linking your local source project to beanstalk, make sure you have initialized a local git repository. Then you can link your workspace and application using eb init. more about EB CLI and Git
Based on my understanding, your question is that you had a project directory on your PC and run your app at the localhost, now you want to run it in the AWS Elastic Beanstalk to make it public.
If you have created an EB application in the EB management console and uploaded your bundled source code, the source code becomes an application version, you need to deploy it into one of your environment using the EB management console, like this:
Figure of the management console.
Then the EB platform(container) will take care of that and run your server automatically as long as you set up the command which your app uses to run the server, the proxy, and other configurations either through the EB management console -> [Your environment] -> configuration or using the .ebextensions file.
If everything is well, you can visit your app's home page through the environment URL at that time.
I have a AWSCodeCommit repository where developers check-in the code. Now since, this is for a PoC, I don't want to create a CI-CD pipeline, instead I would like to copy the code from CodeCommit to my AWS EC2 instance. I would then run my code on EC2 instance to view the results. Does anyone know how to copy the code from CodeCommit to EC2 instance ?. I know using scp to copy code from my laptop to EC2, but since we collaborate on CodeCommit I think it would be nice to get the latest code from repository and then run it on the instance. Any help appreciated. Thanks
Thank you and Regards,
Santosh
Install git
Configure with AWS credentials
Do a git clone on the CodeCommit repository
This will provide a local copy of the code checked into the repository.
See: Setting Up for AWS CodeCommit - AWS CodeCommit
I am new to Amazon Web Services world, and I am implementing Continuous Delivery to the company I work for.
I followed AWS's [instructions to configure CodeCommit Service] (http://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-https-windows.html#setting-up-https-windows-account)
Step 1: Initial Configuration for AWS CodeCommit
To create and configure an IAM user for accessing AWS CodeCommit:
I created a new IAM user and gave him AWSCodeCommitFullAccess
To install and configure the AWS CLI :
I installed and configured the credentials doing aws configure.
Setting AWS Access Key ID, AWS Secret Access Key, Default region name to us-east-1 and de
Step 2: Install Git
I installed Git For Windows making sure the Enable Git Credential Manager option was cleared.
Step 3: Set Up the Credential Helper
git config --global credential.helper "!aws codecommit credential-helper $#"
git config --global credential.UseHttpPath true
Executing:
git config --global --edit
My Configuration is:
[http]
sslVerify = false
[credential]<br>
helper = "aws codecommit list-repositories codecommit credential-helper "
UseHttpPath = true
Step 4: Connect to the AWS CodeCommit Console and Clone the Repository
$ git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/teste-git-to-s3<br>
Cloning into 'teste-git-to-s3'...<br>
git: 'credential-aws' is not a git command. See 'git --help'.<br>
Username for 'https://git-codecommit.us-east-1.amazonaws.com/v1/repos/teste-git-to-s3': Lucas<br>
fatal: unable to access 'https://git-codecommit.us-east-1.amazonaws.com/v1/repos/teste-git-to-s3/': The requested URL returned error: 403
Looking for AWS troubleshooting, I found: Troubleshooting AWS CodeCommit but I couldn't solve it.
How can this be solved?
I think the issue is in your .gitconfig file. Change it to below and it should work.
[credential]
helper = !aws codecommit credential-helper $#
UseHttpPath = true
By the way, if you are using a Bash emulator instead of the Windows command line, you must use single quotes instead of double quotes.
Let me know if this doesn't work.
If you are using cygwin, after you created the repository, click the connect info button, select linux instead of windows, it works on mine.
I experienced this problem with Python 3.8.x - make sure you are using Python 3.7.x instead, as shown in the docs