Demo repository to test cloudfix-linter for cdk
- Install Cloudfix linter extension from here. Extension gets installed on its own on Devspaces.
- Change the value of these constants as per the Ids available in your aws account and deploy the stack.
-
Install the node_modules for the CDK project
npm i
-
AWS Creds setup
-
Login to AWS using terminal (in default profile) by any of the following options:
-
Steps to setup saml2aws for Trilogy account holders -
- run
saml2aws configure
- choose
KeyCloak
as service provider - Provide this url - https://devfactory.devconnect-df.com/auth/realms/devfactory/protocol/saml/clients/aws (url works for trilogy account holders only)
- Enter your AD detials.
- run
-
Note: Setting
AWS_ACCESS_KEY_ID
,AWS_SECRET_ACCESS_KEY
,AWS_SESSION_TOKEN
as enviroment variables from terminal won't work because they are just available in the terminal instance in which have set them and not available globally.
-
-
Select the AWS profile with which AWS was logged in:
- Go to VS Code settings
- Search
cloudfix-linter
- Enter the profile in
AWS Profile
setting
-
Region set up
- The region for profile (chosen in the last step) should also be set to the region where the stack(s) exists. Use the command
aws configure
. Following is an example of setting the region tous-east-1
AWS Access Key ID [****************H44M]: AWS Secret Access Key [****************9jFj]: Default region name [None]: us-east-1 Default output format [None]:
- The region for profile (chosen in the last step) should also be set to the region where the stack(s) exists. Use the command
-
This CDK project has 2 stacks, deploy them (if not done already)
NOTE- Please ensure that you have exported the
ACCOUNT_ID
andREGION
as env vars before deploying resources.- To export
ACCOUNT_ID
andREGION
as env vars and deploy the stack with as per cloudfix-linter run
export ACCOUNT_ID=<YOUR_AWS_ACCOUNT_ID>; export REGION=us-east-1;cdk deploy --all --output .cdkout
Note :-
This will create .cdkout folder in your working directory with all the output from cdk deployment. - To export
-
Run the following command to generate reccos
python utils/gen_recco.py CdkStackmain CdkSimpleResourcesStackmain
-
Use mock cloudfix responses:
- Go to VS Code settings
- Search
cloudfix-linter
- Check
Override Cloud Fix Results For Testing
-
Open one of the typescript files and save it
-
Wait for a few seconds, and the recommendations will show up
-
Follow the step 1 and step 2 mentioned above
-
Add the binary to
PATH
- For linux, macOS, devspaces
export PATH=$PATH:~/.cloudfix-linter/bin
- For Windows
$Env:PATH += ";${HOME}\.cloudfix-linter\bin"
Note: In the following commands replce
cloudfix-linter
withcloudfix-linter.exe
for windows - For linux, macOS, devspaces
-
To check if path to cloudfix-linter has been set that succesfully, Run -
cloudfix-linter --help
Note - If you don't want to set path variable to cloudfix-linter cli. You can use the cli by going inside ~/.cloudfix-linter folder and running the same commands as below
-
To use mock recommendations. In order to generate mock recommnedations and tell the linter that it needs to read reccomendations from a file rather than from CloudFix itself, on the terminal run
- Windows -
$env:CLOUDFIX_FILE=$true python utils/gen_recco.py CdkStackmain CdkSimpleResourcesStackmain
- Linux and Devspaces -
export CLOUDFIX_FILE=true python utils/gen_recco.py CdkStackmain CdkSimpleResourcesStackmain
- Windows
$env:CLOUDFIX_FILE=$false $env:CLOUDFIX_USERNAME="<MY_USERNAME>" $env:CLOUDFIX_PASSWORD="<PASSWORD>"
- Linux and Devspaces
export CLOUDFIX_FILE=false export CLOUDFIX_USERNAME="<MY_USERNAME>" export CLOUDFIX_PASSWORD="<PASSWORD>"
-
To generate lintings on the cdk code run
cloudfix-linter cdk reco
or To get recommendations in json format run
cloudfix-linter cdk reco --json
-
Recommendations will be linted on your Cdk Code.
name
should be exactlyCloudfix-linter CDK Synth
program
should be the absolute path to thecdk
CLI. It can be fetched using the commandwhich cdk
args
should a similar to what is used for deployment but usesynth
in the place ofdeploy
env
can be specified for specifying env vars that the CDK project needs
Sample
{
"version": "0.2.0",
"configurations": [
{
"name": "Cloudfix-linter CDK Synth",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "/home/gitpod/.nvm/versions/node/v14.17.0/bin/cdk",
"args": [
"--app",
"npx ts-node --prefer-ts-exts bin/cdk-project.ts",
"synth",
"--output",
".cdkout"
],
"env": {
"ACCOUNT_ID": "269164092502",
"REGION": "us-east-1"
}
},
]
}