I need to deploy on codebuild in a Different Region - amazon-web-services

I'm trying do a deploy in Ohio from São Paulo, I config the buildspec and the conf on .elasticbeanstalk to set a variable to received us-east as parameter.
I did many tryings to do this work but always the error "EXIT STATUS 4" show. This is my last attempt
COMMAND_EXECUTION_ERROR: Error while executing command: eb deploy Logoneagendamento-teste --region us-east-2. Reason: exit status 4
And the buildspec.yml is as follows
version: 0.2
phases:
install:
runtime-versions:
java: corretto8
commands:
- pip install --upgrade awsebcli awscli
build:
commands:
- echo Iniciando build...
- mvn package
- echo eb list --region
- eb list --region us-east-2
- echo Inciando deploy
- eb deploy $DEPLOY_ENV -r $AWS_DEFAULT_REGION
post_build:
commands:
#- command
#- command artifacts: files: - 'target/LogOne-Agendamento.jar'
# - location #name: $(date +%Y-%m-%d) discard-paths: yes –

Related

AWS CodeBuild failing when building docker image

I'm trying to setup my codebuild pipeline using AWS documentation. Everything goes fine to the moment when CodeBuild starts building docker image with this command
docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
When processing this command AWS is throwing this error
Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .. Reason: exit status 125
ENV variables are set using CodeBuild and locally image building is working with the same command.
My buildspec file
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- IMAGE_TAG=$IMAGE_TAG
- IMAGE_REPO_NAME=$IMAGE_REPO_NAME
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker tag "$IMAGE_REPO_NAME:$IMAGE_TAG" "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG"
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG

How to deploy docker image on EC2 instance using codedeploy?

I am pushing a docker image to ecr repo using the buildspec.yml file. This is what my buildspec.yml look like :-
version: 0.2
phases:
install:
runtime-versions:
nodejs: 16
pre_build:
commands:
- echo Logging in to Amazon ECR.....
- aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <account-id>.dkr.ecr.us-east-1.amazonaws.com
- REPOSITORY_URI=<account-id>.dkr.ecr.us-east-1.amazonaws.com/vuejs
- IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
build:
commands:
- docker build -t $REPOSITORY_URI:$IMAGE_TAG .
post_build:
commands:
- echo Pushing image now...
- docker push $REPOSITORY_URI:$IMAGE_TAG
- printf '[{"name":"vuejs","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
files:
- imagedefinitions.json
- appspec.yml
and this is my appspec.yml file :-
version: 0.0
os: linux
files:
- source: /
destination: /
Now my pipeline ( codepipeline ) passes but how can i configure my appspec.yml file to deploy docker container on my EC2 instance? Any help will be appreciated.

After code deployment, an updated aws cloudformation nested stack custom parameter from console gets its default value

I am trying to update a custom parameter on CloudFormation nested stack from console. It is updated but after code deployment, it gets default value. I want to save last updated value after deployment. I used a bash script as a build command on buildspec.yml. It works if there is a stack but does not work for a stack + a nested stack. Does anyone have any idea about it? I want to use this for updating a parameter from console without code deployment and save it for further usage if it is not changed.
console
publish.sh
mkdir -p build
# SAM Package
aws cloudformation package --template template-build.yml --s3-bucket ${DEPLOYMENT_BUCKET} --output-template build/template.yml --debug
# SAM Deploy
aws cloudformation deploy --template-file build/template.yml --stack-name ${STACK_NAME} --capabilities CAPABILITY_IAM CAPABILITY_AUTO_EXPAND --role-arn ${ROLE_ARN} \
--s3-bucket $DEPLOYMENT_BUCKET \
--parameter-overrides \
DeploymentBucketName=${DEPLOYMENT_BUCKET} \
NodeModulesZipFileName=${packageJsonHash}.zip
buildspec.yml
version: 0.2
phases:
install:
runtime-versions:
python: 3.7
nodejs: 10
commands:
- yum install python3-pip -y
- whereis pip
- pip3 install aws-sam-cli --upgrade --user
- pip3 install awscli --upgrade --user
pre_build:
commands:
- mkdir -p build/
build:
commands:
- echo Build started on `date`
- npm install --only=prod
- chmod +x publish.sh
- bash publish.sh
post_build:
commands:
- echo "no post build needed..."
artifacts:
type: zip
files:
- build/template.yml

CodePipeline unable to find the image definition file

I have created a codebuild whereby the buildspec.yml is as follows (following the standard template given by AWS with minor modifications):
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
- REPOSITORY_URI=xxx.amazonaws.com/projectName
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- IMAGE_TAG=${COMMIT_HASH:=test-cicd}
build:
commands:
- echo Building the docker image...
- docker build -t $REPOSITORY_URI:$COMMIT_HASH -t $REPOSITORY_URI:test-cicd .
- echo Finish building the docker image.
post_build:
commands:
- echo Pushing the docker images...
- docker push $REPOSITORY_URI:$IMAGE_TAG
- docker push $REPOSITORY_URI:test-cicd
- echo Finish pushing the docker images.
- echo Writing image definitions file...
- printf '[{"name":"testcicd","imageUri":"%s"}]' $REPOSITORY_URI:test-cicd > imagedefinitions.json
- cat imagedefinitions.json
artifacts:
files: imagedefinitions.json
The codebuild is successfully pushing the new docker image to ECR and creating the output artifact in S3:
Next I tried to create a codepipeline in which the source is ECR and next stage is to perform codedeploy to ECS. This is the codepipeline created:
However, in the codepipeline status, it shows that the output artifact could not be found:
However, I noticed that the output artifact is indeed in S3!?

Serverless Deploy From another Directory

Here is my root folder and i want to deploy AWS Lambda functions to codecommit from the Backend folder.
Therefore i wrote this command, but AWS CodeBuild gives this error (This command can only be run in a Serverless service directory).
version: 0.1
phases:
install:
commands:
- npm install -g serverless#1.20.2
post_build:
commands:
- cd Backend
- serverless deploy --region eu-west-1 --verbose
How can i deploy it from the backend folder?
Edit: I forgot to edit the version. Now i changed it to version: 0.2 and it works fine.
can you change to
- cd Backend && serverless deploy --region eu-west-1 --verbose
I forgot to edit the version of buildspec.yml. Now i changed it to version: 0.2 and it works fine.
version: 0.2
phases:
install:
commands:
- npm install -g serverless#1.20.2
post_build:
commands:
- cd Backend
- serverless deploy --region eu-west-1 --verbose