How to access Multi-level repo in aws codebuild - amazon-web-services

I have the following repo structure in AWS code commit.
I have MainRepo folder and inside it has 2 sub-folder inside which respective solution and buildspec.yml file present.
I am trying to build proj1.sln using aws codebuild service.
In Source section of aws codebuild, it allows to select MainRepo only.
How can i select sub-folder Repo1 in aws codebuild?

You should create a new CodeCommit Repository first and create the CodeBuild Project from there.
You can follow the steps as below :
Create a new CodeCommit Repository and copy the repository URL from the CodeCommit console.
Clone the CodeCommit Repository from inside your <MainRepo> directory in the local computer (here I am guessing you have the MainRepo directory in your local machine, if not then you can clone it to your local machine)
You will have a new repo directory (eg. <Repo3>) on your local system inside <MainRepo> directory.
Copy the .git folder from <Repo3\.git> to <Repo1\.git> and you can git push your files from <Repo1> to the CodeCommit Repository.
Then you can build your Artifacts/CodeBuild Projects from the newly created CodeCommit Repository.

Related

AWS CodeCommit does support Git LFS?

I have existing project repo in gitlab. Since the gitlab is running in the server, we have the lfs objects in certain directory. My Doubt is AWS Codecommit does not have seperate server to store any lfs configurations as gitlab or bitbucket. I've to configure the lfs directory in AWS CodeCommit. My Question is "Does AWS CodeCommit supports Git LFS?". If yes,can someone explain how to configure AWS CodeCommit with Git LFS?

How to integerate your aws credentials file in codepipeline as I cannot save it in Github repo

Project is built using AWS lambda and some other AWS services. In order to make a build and just to serve a build static files through node express server, it requires the credentials.js file which contains all my AWS credentials of the project.
Now I' making creating an aws codepipeline which pulls the code from GitHub and deploys it on ec2 using elastic beanstalk.
The problem is I don't push my credentials file on Github as it is not secure to do so. And without credentials file the code cannot be deployed. Please suggest me a solution to this problem.
I have already tried placing the file manually in ec2 instance by logging in, but when I make a commit to my repo, the code pipeline executes and it replaces the whole directory of my app in ec2, so the file gets removed.
You can securely store your credentials config file in a private S3 bucket and add commands to your buildspec.yml file (used by the CodeBuild stage of your pipeline) to get that file and put it in the right place for your project.
You will need to give the CodeBuild service role the correct permissions to access the private S3 bucket.
The following is an example of what I mean. Note that I might be storing the config file for multiple environments in S3, so I use an environment variable to specify the exact naming of the file, e.g. my-creds.dev.json or my-creds.prod.json. The filename is then converted to just my-creds.json so you can rely on the same name in your program.
CodeBuild will look for buildspec.yml which defines your build in the root of your project and execute these commands
version: 0.2
phases:
pre_build:
commands:
# Get the creds config file for the correct environment
# and put it in the my projects config directory (or wherever you need it)
- aws s3 cp s3://my-s3-bucket/my-creds.${ENVIRONMENT}.json ./config/my-creds.json
- npm install
build:
commands:
- npm run build:${ENVIRONMENT}
artifacts:
files:
- dist/**/*
The critical line is aws s3 cp s3://my-s3-bucket/my-creds.${ENVIRONMENT}.json ./config/my-creds.json.
The commands are run in the root of your project directory, where the buildspec.yml file is.
The above command is in the pre_build phase so it will run before the commands (npm build) in the build phase are run.
The command copies your credential file from your s3 bucket to the path defined by the last part of the command (in this case ./config/my-creds.json). Again remember this is relative to the root of your project directory, so if your project contains a src folder in the root directory, then your path might be ./src/my-creds.json, or ./src/creds/my-creds.json.
You should not add the credentials file as it is not recommended. You can do the deployment by assigning a role to your code pipeline with permission to access the required resources.

Is there any way to use an external private maven repository like S3 Bucket in AWS Code Build plan instead of using the default central maven repo?

I'm trying to create an AWS code build project to build my project linking to AWS code commit, but I would replace the default central maven repository with my private repo on S3 Bucket. I wouldn't like to modify pom.xml, and instead want to config the AWS Build plan to fetch the dependencies from my S3 Bucket.

AWS CodeBuild pipeline CodeCommit git repo path

If I configure a CodeBuild pipleline as using the CodeCommit Source provider, what is the path of the source code (git repo) to refer to in the buildspec.yml commands?
Use the predefined environment variable "CODEBUILD_SRC_DIR". Details: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html

alternate appspec.yml location for AWS CodePipeline/CodeDeploy

i'm learning AWS-based continuous integration and have a basic CodeCommit → CodePipeline → CodeDeploy workflow setup per the tutorial. when i push to CodeCommit, CodePipeline triggers a build in CodeDeploy, however it does not find my appspec.yml manifest because it's not in the root of my repository.
how do i configure CodePipeline/CodeDeploy to look for appspec.yml under the subdirectory inst/aws/ instead of the repository root? i don't want to restructure my repo (which also has non-AWS content) just to accommodate a vendor-specific preference.
By default CodeDeploy agent looks at the root of your bundle for appspec.yml. Unfortunately you can't configure the location of the appspec.
You can do that with the use of AppSpecTemplatePath.
The file name of the AppSpec file stored in the pipeline source file
location, such as your pipeline's CodeCommit repository. The default
file name is appspec.yaml. If your AppSpec file has the same name and
is stored at the root level in your file repository, you do not need
to provide the file name. If the path is not the default, enter the
path and file name.
Source: https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-ECSbluegreen.html#action-reference-ECSbluegreen-type