Reputation: 456
I am fairly new to cdk. How do I set up cdk or cdk.json to run where the python executable may be named 'python' or 'python3' depending on the platform ?
cdk init --language python creates the cdk.json on my local Windows PC with the line
"app": "python app.py"
The failure occurs when Jenkins CI/CD executes the application. Jenkins build fails because the linux based Jenkins expects 'python3'.
Current solution is to edit cdk.json when we commit to github and Jenkins auto builds the lower environments. Is there a better way?
Upvotes: 0
Views: 2159
Reputation: 31
I had a few problems, but in the end, using python3 in the cdk.json file made no difference. I have a windows OS. The pre-requisites were:
Having this, I executed the line below in my windows terminal
npm install -g aws-cdk
Next step in my project (I use vscode), I created a folder to execute cdk (and I named it "cdk" but it could be anything).
Before executing cdk deploy, execute the pip install -r requirements.txt and use cdk synth to test if everything is ok or if some error must be corrected.
When using git actions, use sudo before the npm command and add in the run command the cd so git can navigate until the cdk folder. Without those, I had the error that follows. --app is required either in command-line, in cdk.json or in ~/.cdk.json
Here's how the deploy job was configurated in my git actions file:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- uses: actions/setup-node@v2-beta
with:
node-version: '12'
- name: Install dependencies
run: |
sudo npm install -g aws-cdk
cd 2_continuous_integration_and_tests/CDK
pip install -r requirements.txt
- name: Deploy
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
run: |
cd 2_continuous_integration_and_tests/CDK
cdk synth
cdk deploy
Kind regards ;)
Upvotes: 1
Reputation: 621
Using python3 directly in cdk.json
:
{
"app": "python3 app.py",
"context": {
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true",
"@aws-cdk/core:stackRelativeExports": "true",
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true
}
}
Or alias python symlink
to python3
:
lrwxrwxrwx 1 root root 18 Nov 8 14:20 /usr/bin/python -> /usr/bin/python3.8
Upvotes: 1