I'm trying to build & deploy a simple sample project to learn AWS. C# / .NET Core.
My buildspec looks like this:
version: 0.2
phases:
install:
runtime-versions:
dotnet: 2.2
pre_build:
commands:
- echo Restore started on `date`
- dotnet restore AWSServerless1.csproj
build:
commands:
- echo Build started on `date`
- dotnet publish -c release -o ./build_output AWSServerless1.csproj
artifacts:
files:
- ./build_output/**/*
- scripts/**/*
- appspec.yml
discard-paths: yes
My appspec looks like this:
version: 0.0
Resources:
- myStack-AspNetCoreFunction-1HPKUEU7I6GFW:
Type: AWS::Lambda::Function
Properties:
Name: "myStack-AspNetCoreFunction-1HPKUEU7I6GFW"
Alias: "AWSServerless1"
CurrentVersion: "1"
TargetVersion: "2"
The pipeline completes successfully, but when I try to run the lambda, I get a 502. I checked the logs and it says:
Could not find the required 'AWSServerless1.deps.json'. This file should be present at the root of the deployment package.: LambdaException
When I download the package from S3, to me, it looks like everything is there. It's a zip file, no paths anywhere, everything is in the root of the zip including AWSServerless1.deps.json.
Any ideas?
Use dotnet lambda package instead of publish
see https://github.com/aws/aws-extensions-for-dotnet-cli
Related
I've set up a build job that uses batch builds.
2 batches will build something, upload to S3 and output the location in a json file.
The last batch is supposed to pick up the two json files and use them in some further things.
My problem: I can't find the artifacts in the last job.
When I use ls in the first 2 jobs, they are there - but not in the last one.
Here is my buildspec, with unimportantt parts removed.
version: 0.2
batch:
fast-fail: true
build-graph:
- identifier: template_examplehook
- identifier: s3_checkbucketencryptionhook
- identifier: stackset
buildspec: automation/assemble-template.yaml
depend-on:
- template_examplehook
- s3_checkbucketencryptionhook
phases:
install:
runtime-versions:
python: 3.7
pre_build:
commands:
- echo "Starting ..."
- ...
build:
commands:
- echo "Building with $(python --version)"
- cd $CODEBUILD_BATCH_BUILD_IDENTIFIER
- ---
- echo $S3_URI_PACKAGE > hash.json
- ---
post_build:
commands:
- echo Build completed on $(date)
artifacts:
files:
- '*/hash.json'
I expected to find the hash.json file in their respective folders but they don't exist in the last batch job.
Update after talking to our AWS tech support:
Unexpected behaviors, it should work as we thought it would, but it doesn't.
We ended up rewriting it and went with two different build steps.
When I try to deploy the app the build completes without errors. When I go to the link provided (https://master.d3m2wky0hslwhr.amplifyapp.com/) I get ERR_TOO_MANY_REDIRECTS .
My build config:
version: 1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
# IMPORTANT - Please verify your build output directory
baseDirectory: .nuxt
files:
- '**/*'
cache:
paths:
- node_modules/**/*
Inside the app I have (index.vue, login.vue and register.vue)
I think it may be because im beeing redirected to url/index.html and that file does not exist in the proyect.
Solved it.
Change -npm run build to -npm run generate
(This creates the index.html by default and converts everything to static)
Change baseDirectory to dist
Base on AWS Code Build documentation, we can pass EnvironmentVariables with PARAMETER_STORE type.
I've ensure the parameter store name is typed correctly and the parameter is exists.
I've tried to login via aws cli but it seem not related and still get wrong result.
Here is my cloudformation yaml snippet:
- Name: Build
Actions:
- Name: HelloWord
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: "1"
Configuration:
ProjectName: HelloWoldBuild
EnvironmentVariables:
Fn::Sub:
- '[{"name": "NGINX_BASE_IMAGE_TAG","value": "${NGINX_BASE_IMAGE_TAG}","type": "PARAMETER_STORE"}]
- NGINX_BASE_IMAGE_TAG: "/nginx/base"
and here is my buildspec.yaml snippet:
version: 0.2
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
- echo "${NGINX_BASE_IMAGE_TAG}"
When I see the CodeBuild log, the output was '***'. The correct one should be value from my parameter store.
How could it happen ? I still don't get it. I've test with PLAINTEXT type and works well.
This is by design.
Values from parameter store are considers as sensitive.
So CodeBuild masks them so they don't appear in plain text in its logs.
To deal with that, you can assign it to different variable, and print that. The following would be my first try to deal with that:
pre_build:
commands:
- NEW_VAR=${NGINX_BASE_IMAGE_TAG}
- echo "${NEW_VAR}"
Alternative. Save it to file and print out a file:
pre_build:
commands:
- echo ${NGINX_BASE_IMAGE_TAG} > /tmp/test.value
- cat /tmp/test.value
In my existing aws pipeline I have the following buildspec.yml:
version: 0.2
phases:
build:
commands:
- cd media/web/front_dev
- echo "Hello" > ../web/txt/hello.txt
artifacts:
files:
- ./media/web/hello.txt
And the appspec.yml has the following
version: 0.0
os: linux
files:
- source: /
destination: /webserver/src/public
But the file hello.txt is not being deployed to the server on the deploy phase? Once I ssh into the machine I run the following commands:
/webserver/src/public/media/web/hello.txt
But the file is not shown. Do you have any idea why?
My pipeline initially had only a source and a deployment step then I edited it in order to have a codebuild step as well.
Check your pipeline. You may have added the build step but the deployment just fetches the code from the version control instead of the deployment. In order to solve that follow these steps:
Specify a name for the output artifact at the build step.
Select as input artifact the artifact you have placed into as output artifact at the build step.
I have googled and searched within stackoverflow and found some suggestions but still no succedd. My build process in AWS Codebuild runs and gives me a success output but in the log shows -> 'No artifact files specified', and as the result no files are being copied in my S3. Could anybody help me figure this out. Here I share my yml setting:
version: 0.1
phases:
build:
commands:
- echo Nothing to do yet
addons:
artifacts:
s3_region: "eu-central-1"
files:
- '**/*'
I suggest you refer to the Build Specification Reference.
Specifically, you should remove addons: as well as s3_region: as neither of these are valid CodeBuild flags. You should also be using version: 0.2, as version: 0.1 has been deprecated.
Here is what your buildspec.yml should look like:
version: 0.2
phases:
build:
commands:
- echo Nothing to do yet
artifacts:
files:
- '**/*'