Created
October 8, 2025 15:10
-
-
Save darko-mesaros/83fb1c1a69a2169bd296e0ddd343d792 to your computer and use it in GitHub Desktop.
Justfile I used for some CDK development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Extract values with fallbacks using `jq` and shell fallbacks | |
| USER_POOL_ID := `jq -r '.RustyLocksStack.userPoolId // "NOT_DEPLOYED"' outputs.json 2>/dev/null || echo "NOT_DEPLOYED"` | |
| CLIENT_ID := `jq -r '.RustyLocksStack.userPoolClientId // "NOT_DEPLOYED"' outputs.json 2>/dev/null || echo "NOT_DEPLOYED"` | |
| API_URL := `jq -r '.RustyLocksStack.apiUrl // "NOT_DEPLOYED"' outputs.json 2>/dev/null || echo "NOT_DEPLOYED"` | |
| DISTRIBUTION_ID := `jq -r '.RustyLocksStack.distributionId // "NOT_DEPLOYED"' outputs.json 2>/dev/null || echo "NOT_DEPLOYED"` | |
| # User credentials | |
| EMAIL := "[email protected]" | |
| PASSWORD := "TestPass123!#" | |
| # Deploy and save outputs | |
| deploy: | |
| @echo "⏳Deploying the CDK stack..." | |
| npx cdk deploy --outputs-file outputs.json | |
| # Generate the config file for JavaScript | |
| generate-config: | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| if [ "{{USER_POOL_ID}}" = "NOT_DEPLOYED" ]; then | |
| echo "❌ Stack not deployed. Run 'just deploy' first." | |
| exit 1 | |
| fi | |
| echo "⏳Generating config.js" | |
| cat > dist/config.js << EOF | |
| const CONFIG = { | |
| region: 'us-west-2', | |
| userPoolId: '{{USER_POOL_ID}}', | |
| clientId: '{{CLIENT_ID}}', | |
| }; | |
| EOF | |
| echo "✅ Generated dist/config.js" | |
| # Deploy with config.js | |
| deploy-with-config: deploy generate-config | |
| npx cdk deploy | |
| @echo "✅ Deployed with fresh config.js" | |
| # Invalidate CDN Cache | |
| invalidate-cache: | |
| @echo "⏳Clearing the CDN Cache..." | |
| aws cloudfront create-invalidation --distribution-id {{DISTRIBUTION_ID}} --paths "/*" | |
| # Create the test user | |
| create-user: | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| echo "⏳Creating test user" | |
| if [ "{{USER_POOL_ID}}" = "NOT_DEPLOYED" ]; then | |
| echo "❌ Stack not deployed. Run 'just deploy' first." | |
| exit 1 | |
| fi | |
| aws cognito-idp admin-create-user \ | |
| --user-pool-id {{USER_POOL_ID}} \ | |
| --username {{EMAIL}} \ | |
| --user-attributes Name=email,Value={{EMAIL}} Name=email_verified,Value=true \ | |
| --temporary-password TempPass123! \ | |
| --message-action SUPPRESS | |
| echo "✅ Test user created." | |
| # Set a permanent password to the test user | |
| set-password: | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| echo "⏳Setting password" | |
| if [ "{{USER_POOL_ID}}" = "NOT_DEPLOYED" ]; then | |
| echo "❌ Stack not deployed. Run 'just deploy' first." | |
| exit 1 | |
| fi | |
| aws cognito-idp admin-set-user-password \ | |
| --user-pool-id {{USER_POOL_ID}} \ | |
| --username {{EMAIL}} \ | |
| --password {{PASSWORD}} \ | |
| --permanent | |
| echo "✅ Test user password set." | |
| # Delete the test user | |
| delete-user: | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| echo "⏳Deleting test user" | |
| if [ "{{USER_POOL_ID}}" = "NOT_DEPLOYED" ]; then | |
| echo "❌ Stack not deployed. Run 'just deploy' first." | |
| exit 1 | |
| fi | |
| aws cognito-idp admin-delete-user \ | |
| --user-pool-id {{USER_POOL_ID}} \ | |
| --username {{EMAIL}} | |
| echo "✅ Test user deleted." | |
| # Generate JWT token (with check) | |
| get-token: | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| echo "⏳Getting Token" | |
| if [ "{{USER_POOL_ID}}" = "NOT_DEPLOYED" ]; then | |
| echo "❌ Stack not deployed. Run 'just deploy' first." | |
| exit 1 | |
| fi | |
| aws cognito-idp admin-initiate-auth \ | |
| --user-pool-id {{USER_POOL_ID}} \ | |
| --client-id {{CLIENT_ID}} \ | |
| --auth-flow ADMIN_NO_SRP_AUTH \ | |
| --auth-parameters USERNAME={{EMAIL}},PASSWORD={{PASSWORD}} \ | |
| --query 'AuthenticationResult.IdToken' \ | |
| --output text > .token | |
| echo "✅ Token aquired." | |
| # Run the auth prep steps | |
| auth-prep: create-user set-password get-token | |
| @echo "⏳Preparing auth for test" | |
| @echo "✅ Auth ready. Run your tests." | |
| # Test GET /locks (with check) | |
| test-get: | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| if [ "{{API_URL}}" = "NOT_DEPLOYED" ]; then | |
| echo "❌ Stack not deployed. Run 'just deploy' first." | |
| exit 1 | |
| fi | |
| http GET {{API_URL}}/api/locks Authorization:"Bearer $(cat .token)" | |
| # Clean up | |
| clean: | |
| rm -rf ".token" && rm -rf "outputs.json" | |
| bye: clean | |
| cdk destroy --force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment