This repository is a chitin fiber containing a collection of helpers for cloud engineering.
Clone this repository to your project dir
(the directory where you usually run git clone
).
Requires:
aws
,jq
There are several AWS helper subchains, broken out by service.
{
"chains": {
"aws": {
"enabled": "boolean; whether to load the chain",
"envEnabled": "boolean; whether to enable the aws-env chain",
"googleUsername": "string; your full email address",
"departmentRole": "string; the AWS org you are a member of [optional]",
"defaultProfile": "string; the role to automatically assume [optional]",
}
}
}
The aws-env
chain is designed to reduce friction in AWS authentication, automatically configuring your aws
CLI to work with all our accounts and roles, and enabling you to easily switch between them.
This shell integration is disabled by default, but you can enable it by setting aws.envEnabled: true
in step 3 of the setup. This is recommended, but not required.
To switch between AWS organizations (if you are a member of multiple):
awsOrg engineering-data
To assume a particular AWS role, authenticating if needed:
awsAuth dataeng-dev-admin
To reset your AWS credentials (which can be useful for debugging):
deAuth
Functions:
awsId
: prints your full identity if authenticated, or failsawsAccount
: prints your account alias if authenticated, or failsawsAccountId
: prints your account id if authenticated, or failsawsRole
: prints your currently-assumed IAM role if authenticated, or failsdeAuth
: removes authentication, can be used for testing/resettingcheckAuthAndFail
: checks if you're authenticated, or fails. meant to be used as a failfastcheckAccountAuthAndFail
: checks if you're authenticated with a specific account, or fails. meant to be used as a failfast
If you enable the shell integration, you can use the following functions to assume roles:
awsOrg
: switch to a different AWS organization, needed only ifDEPT_ROLE
not setawsAuth
: authenticate if needed, and assume a profilewithProfile
: run a command with a specific AWS profile
Functions
awsAsgGetTags
: gets the tags for the ASG with the given name
Functions
awsIamListRolePolicies
: shows all policy attachments for a given roleawsIamListUserPolicies
: shows all policy attachments for a given userawsIamGetPolicy
: fetches a policyawsIamShowCurrentRolePermissions
: shows all policy attachments and their allowed actions for the current roleawsIamGetPolicyAttachments
: shows all policy attachments for a given policy versionawsIamShowPolicy
: shows all policy attachments and their allowed actions for a given policy versionawsIamAssumeRoleShell
: assumes an IAM role in a subshell, can be used to test permissions
Functions:
awsEbsWatchVolumeModificationProgress
: watches an EBS volume currently being modified and reports progressawsEbsWatchSnapshotProgress
: watches an EBS volume snapshot currently being created and reports progressawsCheckAZ
: checks whether an availability zone with the given name existsawsEbsFindSnapshots
: finds the ids of EBS snapshots with the given name, in descending-recency orderawsEbsFindSnapshot
: finds the id of the latest EBS snapshot with the given nameawsEbsDeleteSnapshots
: deletes all EBS snapshots with the given nameawsEbsShowVolumeTags
: shows the tags on an EBS volumeawsEbsTagVolume
: adds a tag to an EBS volumeawsEbsCreateVolume
: creates an EBS volume with the given name, either empty or from a snapshotawsEbsFindVolumesByName
: finds the ids of the EBS volumes with the given nameawsEbsListSnapshots
: lists all EBS snapshots in the account, with namesawsEbsListInProgressSnapshots
: lists all in-progress EBS snapshots in the account, with namesawsEbsListVolumes
: lists all EBS volumes in the account, with namesawsEbsModifyVolumeIOPS
: sets the IOPS for the EBS volume with the given name or idawsEbsResizeVolume
: resizes the EBS volume with the given name or idawsEbsSnapshotVolume
: snapshots the EBS volume with the given name or idawsEbsWaitUntilSnapshotReady
: polls the status of the given EBS snapshot until it is availableawsEbsDeleteVolume
: deletes the EBS volumes with the given name or idawsEbsAuthorizeSnapshotAccess
: authorizes access to a snapshot from another accountawsEbsCopySnapshotCrossAccount
: authorizes access to, and then copies a snapshot across to another account
Functions:
awsEc2ListInstances
: lists existing EC2 instancesawsEc2FindInstancesByName
: finds the ids of the EC2 instances with the given nameawsEc2ListKeypairs
: lists existing EC2 keypairsawsEc2CheckKeypairExistence
: checks that a given EC2 Keypair existsawsEc2CreateKeypair
: creates an EC2 keypair and persists it in SSMawsEc2DeleteKeypair
: deletes an existing EC2 keypair and removes it from SSMawsEc2DownloadKeypair
: reads a given EC2 Keypair out from SSM, persists locally, and permissions for useawsEc2GetInstanceKeypairName
: queries the name of the keypair used for the given EC2 instanceawsEc2DownloadKeypairForInstance
: queries the appropriate keypair for an EC2 instance and downloads itawsEc2ListNetworkInterfaceAddresses
: lists all ENIs along with their associated private IP addressesawsEc2GetNetworkInterface
: gets the description for a given ENI
Functions:
awsR53ListZones
: lists all hosted zonesawsR53GetZoneId
: finds the id of the Route 53 hosted zone the given nameawsR53GetRecords
: gets all records in the given hosted zoneawsR53GetARecords
: gets all A records in the given hosted zone
Functions:
awsRdsCheckSnapshotExistence
: checks the existence of an RDS snapshot with the given nameawsRdsWaitUntilSnapshotReady
: polls the status of the given RDS snapshot until it is availableawsRdsDeleteSnapshot
: waits for the RDS snapshot with the given name to be available, and then deletes itawsRdsCheckInstanceExistence
: checks the existence of an RDS instance with the given nameawsRdsSnapshot
: snapshots the given RDS instance
Functions:
awsS3ListBuckets
: lists existing S3 bucketsawsS3ReadObject
: downloads and reads the content of a particular S3 objectawsS3KeyExists
: check if the given key in the given s3 bucket exists
Functions:
awsSsmListParams
: lists all SSM parameter namesawsSsmGetParam
: fetches and decrypts an SSM parameterawsSsmSetParam
: sets an SSM parameterawsSsmDeleteParam
: deletes an SSM parameter
Functions:
awsMskListClusters
: lists all MSK clusters in the account, with namesawsMskFindClusterArnByName
: finds the ARN of the MSK cluster with the given nameawsMskGetConnection
: gets the connection string of the MSK cluster with the given identifierawsMskGetZkConnection
: gets the Zookeeper connection string of the MSK cluster with the given identifierawsMskGetBrokers
: gets the broker list of the given MSK cluster with the given identifierawsMskGetBrokerArns
: gets the list of broker ARNs of the given MSK cluster with the given identifierawsMskRebootBroker
: reboots the MSK broker with the given cluster identifier and broker ID
Functions:
awsDynamoListTables
: lists all DyanmoDB tablesawsDynamoListTableItems
: lists all items in the given DynamoDB tableawsDynamoGetItem
: gets a specific DynamoDB itemawsDynamoUpdateItem
: updates the value of a specific DynamoDB item
Functions:
helmReadRepoConfig
: prints out the local Helm repository configurationhelmRepoChecConfigured
: s whether a given Helm repository is configuredhelmRepoConfigureArtifactory
: configures the Artifactory Helm repositoryhelmRepoGetCredentials
: prints a JSON object containing the locally-configured credentials for the given repositoryhelmRepoGetArtifactoryCredentials
: prints a JSON object containing the locally-configured Artifactory credentialshelmChartGetLatestRemoteVersion
: gets the latest version of a given helm charthelmChartCheckRemoteVersion
: checks whether the given version of the given helm chart existshelmChartGetLocalVersion
: gets the version of a local Helm charthelmChartGetLatestVersion
: gets the latest version of a given Helm charthelmChartCheckVersion
: checks the version of a given Helm chart against a desired version
The k8s-env
helper sets up your Kubernetes configuration for working with our EKS environments. It works by generating a eksconfig.yaml
file and adding it to your KUBECONFIG
environment variable. A set of known clusters is packaged with this tool, and you can add your own clusters in the eksClusters
field of the chain config like so:
{
"chains": {
"k8s-env": {
"eksClusters": {
"example-prod": {
"name": "example-prod-test-cluster",
"role": "example-prod-admin"
}
}
}
}
}
This shell integration is disabled by default, but you can enable it by setting k8s-env.enabled=true
. This is recommended, but not required. If you do choose to use it, however, you may want to delete any existing EKS-relevant config from your ~/.kube/config
file, to avoid conflicts.
Functions:
k8sGetCurrentContext
: gets the current k8s context configk8sDeleteContext
: deletes a k8s context
Requires:
kubectl
,yq
,jq
,fzf
(optional)
The K8s helper provides useful functions for interacting with clusters and various associated administrative tasks.
Note: these functions use the shell's current context/namespace. Please ensure you set them appropriately using
kubectx/kubens
before running.
Functions:
k8sDebugPod
: launches a debug pod in the cluster preloaded with common networking tools, drops you into its shell when createdk8sDownDeploy/k8sUpDeploy/k8sReDeploy
: stop/start/restart a deploymentk8sDownDeployAndWait
: scales down a deployment to 0 replicas, and awaits the operation's completionk8sSecretEncode
: base64-encodes a string for use in a Secretrds
: connects to an RDS instance from the service namegetServiceExternalUrl
: fetches the external url, with port, for a Service with a load balancer configuredgetServiceEndpoint
: fetches the endpoint url for both services and proxies to zen gardenk8sKillDeploymentPods
: kills all pods for a deployment, useful for forcing a restart during devk8sGetImage
: gets the container image for a given resourcek8sGetServiceAccountToken
: gets the token for a given ServiceAccountk8sCreateTmpSvcAccContext
: creates a temporary k8s context for a ServiceAccountk8sRunAsServiceAccount
: impersonates a given ServiceAccount and runs a commandkubectlAsServiceAccount
: impersonates a given ServiceAccount and runs a kubectl command using its tokenk8sGetResourceAnnotation
: gets an annotation value for the given resourcek8sGetServiceExternalHostname
: gets the external hostname created for a given Servicek8sGetDeploymentSelector
: gets the pod selector used for a given Deploymentk8sGetDeploymentPods
: gets the pods managed by a given Deploymentk8sDeploymentHasPods
: checks whether a given Deployment has running pods under managementk8sWaitForDeploymentScaleDown
: waits until all pods under management of a given Deployment have scaled down
Requires:
docker
,python
Functions:
kafkaListTopics
: lists all known topicskafkaReadTopic
: reads from a topic at a certain offsetkafkaResetTopics
: resets an MSK cluster's topics by destroying and recreating using terraformkafkacli
: tool to query tx-producer kafka topics
Requires:
terraform
,jq
Functions:
tfRun
: runs the specified terraform command in on a particular moduletfShowDestroys
: generates a terraform plan and shows destructive actionstfCopyState
: copies the Terraform remote statetfBackupState
: backs up a Terraform remote state filetfRestoreState
: restores a Terraform remote state file backuptfDynamoLockKey
: get a specific TF remote state lock itemtfGetLockTableItem
: get a specific TF remote state lock digesttfUpdateLockDigest
: set a specific TF remote state lock digesttfSourceToLocal
: convert a terraform module source to a local path, useful for developmenttgMigrate
: runs a tfMigrate migration usingterragrunt
tgGetSource
: reads the terragrunt module sourcetgSourceToLocal
: converts the terragrunt module source to a local pathtgSourceToRemote
: converts the terragrunt module source to a github URLtgGoToLocalSource
: navigates to the terragrunt source module locallytgGoToRemoteSource
: opens the terragrunt module source in the browser