How to get AWS credentials for Jenkins + ECR + Pipeline - amazon-web-services

I am currently building Jenkins + ECR CI/CD.
Here's pipeline code.
docker.withRegistry(
'https://ID.ecr.eu-west-1.amazonaws.com',
'ecr:eu-west-1:86c8f5ec-1ce1-4e94-80c2-18e23bbd724a') {
My Question is How can I get ECR login credential?
The login credential in the above code is 'ecr:eu-west-1:86c8f5ec-1ce1-4e94-80c2-18e23bbd724a'.
My reference documentation is https://plugins.jenkins.io/amazon-ecr/

Install AWS Pipeline Plugin in Jenkins,
Then you can create an aws credential from Manage Jenkins - Manage credentials

Open a freestyle job. You can find "Credentials" under git or docker. Choose one to click add. The default credential provider is jenkins. Click it and choose "AWS credential". Fill amazon access key ID and access key and submit.
Go to "Manage Jenkins" and then "Manage Credentials". You can find credential id.

Related

Api credentials for AWS ECR

I created a new AWS account for AWS ECS. IN Jenkins I installed AWS ECS plugin and now I want to build and push images into registry.
But I need to create API key and secret in AWS in order to Jenkins to communicate with AWS ECR.
How I have to create in AWS these credentials?
Create an IAM user by following this documentation:
https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html

How do I Use credentials from AWS Secret Key manager in Jenkins Jobs

The task is to use the credentials from the AWS secret manager in Jenkins Jobs configure section.
Am using the "AWS Secrets Manager Credentials Provider" plugin in Jenkins, but after integration, I can only use was CLI commands alone.
Here while integrating this plugin in cloud bees video I noticed that we need to enter the AWS secret key ID and Access key sysconfig file under JAVA_OPTIONS.
But I couldn't find the sysconfig file in my Jenkins.
Can someone help here on this?
Please let me what is the proper way to integrate AWS Secret key manager with Jenkins ?

How can codeBuild container run aws-cli commands without prior authentication?

Say I use aws-cli locally on my machine, I´d need to authenticate with credentials prior to any operation.
How do AWS services give permission to other services on my behalf? And more specifically, how does a container run aws-cli on my behalf without prior authentication?
I am asking this, after running my first pipeline successfully in codePipeline. My buildspec.yml does run aws s3 sync command flawlessly -which made me then wonder how do aws internally permissions work-.
AWS CodeBuild uses an IAM Service Role to provide AWS permissions to the CodeBuild environment. You should have had to create a service role for your CodeBuild configuration.
When the AWS cli tool runs, and it hasn't been previously configured with API access keys, it will check if it is running in an AWS environment like EC2 or Lambda and if so, it will use the AWS IAM role assigned to that runtime environment.

AWS plugin on Jenkins

I'm trying to use Jenkins as a build server hosted on aws. For that I have an EC2 instance with Jenkins up and running. I installed the AWS EC2 plugin but when I try to configure it (by going to jenkins -> configure system -> add cloud -> aws) I get the following error:
Stack trace
com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain
at com.amazonaws.auth.AWSCredentialsProviderChain.getCredentials(AWSCredentialsProviderChain.java:131)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.getCredentialsFromContext(AmazonHttpClient.java:
I can't even fill in the AWS credentials.
Anybody have any thoughts on this?
some people have worked around this error by not ticking the "IAM Role" checkbox when configuring AWS.
see open jenkins issue: S3 plugin - Unable to load AWS credentials from any provider in the chain
see also stackoverflow question: Unable to load AWS credentials from any provider in the chain - Jenkins & AWS codepipeline

AWS - Elastic Beanstalk CLI - how to list/change profiles

I have two AWS accounts, one for personal, one for work-related projects. I've previously created and deployed to my personal AWS account.
I want to create a work-related app on the work AWS account. I signed in with those credentials, and created a new application from within the console.
Then, in my work project folder, I eb init and eb create/deploy the work app. When I did eb create, it was asking to set up a an environment different than the one I had created in AWS. After creating it, I found that a new project had be created within my personal AWS account.
I was told I have to change profiles doing eb --profile but am not sure of my profile names. How can I list and change my profile from my personal to my work profile?
EDIT:
I was given an access key ID. I tried eb --profile MYKEYID. No message was displayed when I did this. I'm not sure which profile I'm on.
The EB CLI and the AWS CLI share the same credentials.
They are stored in either ~/.aws/config or ~/.aws/credentials.
You can list them using
aws configure list
Once you know what profile you want to use, you can set it permanently for that project by running
eb init --profile ProfileName
in the project directory.
You can see what settings the EB CLI has for your project by looking at the .elasticbeanstalk/config.yml file.