alternate appspec.yml location for AWS CodePipeline/CodeDeploy - amazon-web-services

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

Related

How to upload zip file from S3 to Lambda using CodeDeploy

Since i'm not able to comment to the question: How to deploy ziped lambda code from s3 using code deploy service alone? i need to ask it again. I'm using AWS CodeBuild to use my Code from CodeCommit for creating Artifacts. I'd like to use those Artifacts as Input for my lambda functions. I'M NOT USING SAM.
I have an appspec.yml in my repo and can build it as second artifact on my bucket so deploy is able to find and "deploy" it but the main problem remains: the code doesn't get updated to the contents of the zip file. Regardless of I'm using a zip or a dir and regardless of I'm placing the appspec in my unzipped artifact or next to my zipped artifact. I've found this video: https://youtu.be/mYcRPKeCPXc. But I just don't get how his code is being updated without mentioning his zip file anywhere.

Code deploy agent unable to find appspec.yml file

I am trying to perform CI/CD workflow on ec2 instance using aws codedeploy but I am getting below error at the time of deployment:
The CodeDeploy agent did not find an AppSpec file within the unpacked revision directory at
revision-relative path "appspec.yml".
How can I create appsepc.yml file in order to succeed deployment.As I doing it first time.Someone let me know.
Exact setup of appsepc.yml is use-case specific, and it has to be tailored to your application requirements. Thus you are the only one who can create it.
But AWS provides examples of such files:
AppSpec File example for an EC2/On-Premises deployment
aws-codedeploy-samples
appspec.yml file is what instructs the codedeploy agent on what are the steps to run on the EC2 instances. You can find the detailed structure and example provided by AWS

How to access Multi-level repo in aws codebuild

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.

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.

"BundleType must be either YAML or Json" Error using Jenkins and AWS CodeDeploy

I am trying to deploy revisions to my AWS lambda functions using Jenkins and the AWS CodeDeploy add-on. I am able to build the project successfully and upload a zip of the project to an S3 bucket. At this point I receive the error:
BundleType must be either YAML or JSON
I have an appspec.yml file in my code directory. I am unsure if I need to instruct Jenkins to do something different, or if I need to instruct AWS to unzip the file and use it.
Today CodeDeploy lambda deployment only take in a YAML or JSON file as deployment revision input (which is just your AppSpec file). Today CodeDeploy Jenkins plugin needs to be updated to support uploading YAML or JSON file without zipping it: https://github.com/jenkinsci/aws-codedeploy-plugin/blob/master/src/main/java/com/amazonaws/codedeploy/AWSCodeDeployPublisher.java#L230