Skip to content

Instantly share code, notes, and snippets.

@avoidik
Created May 26, 2025 14:07
Show Gist options
  • Save avoidik/306b740fa4481e2cce29dffae571c122 to your computer and use it in GitHub Desktop.
Save avoidik/306b740fa4481e2cce29dffae571c122 to your computer and use it in GitHub Desktop.
AWS CloudShell API

Create environment

$ jq --arg env_name 'vscode-aws-cloudshell' --arg vpc_id 'vpc-XYZ' --arg sg_id 'sg-123' --arg subnet_id 'subnet-ABC' -n \
    '.EnvironmentName = $env_name | .VpcConfig.VpcId = $vpc_id | .VpcConfig.SecurityGroupIds = [$sg_id] | .VpcConfig.SubnetIds = [$subnet_id]' | \
    curl -s --location --request POST 'https://cloudshell.eu-central-1.amazonaws.com/createEnvironment' \
    --header 'Content-Type: application/json' \
    --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
    -H "x-amz-security-token: $AWS_SESSION_TOKEN" \
    --aws-sigv4 "aws:amz" \
    --json @- | jq -r

{
  "StartScreenMessages": [],
  "EnvironmentId": "abcdefgh-aaaa-bbbb-cccc-dddddddddddd",
  "Status": "CREATING"
}

Describe environments

$ jq --arg env_id 'abcdefgh-aaaa-bbbb-cccc-dddddddddddd' -n '.EnvironmentId = $env_id' | \
curl -s --location --request POST 'https://cloudshell.eu-central-1.amazonaws.com/getEnvironmentStatus' \
--header 'Content-Type: application/json' \
--user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
-H "x-amz-security-token: $AWS_SESSION_TOKEN" \
--aws-sigv4 "aws:amz" \
--json @- | jq -r

[
  {
    "EnvironmentId": "abcdefgh-aaaa-bbbb-cccc-dddddddddddd",
    "VpcConfig": {
      "VpcId": "vpc-XYZ",
      "SecurityGroupIds": [
        "sg-123"
      ],
      "SubnetIds": [
        "subnet-ABC"
      ]
    },
    "EnvironmentName": "vscode-aws-cloudshell"
  }
]

Get environment status

$ jq --arg env_id 'abcdefgh-aaaa-bbbb-cccc-dddddddddddd' -n '.EnvironmentId = $env_id' | \
curl -s --location --request POST 'https://cloudshell.eu-central-1.amazonaws.com/getEnvironmentStatus' \
--header 'Content-Type: application/json' \
--user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
-H "x-amz-security-token: $AWS_SESSION_TOKEN" \
--aws-sigv4 "aws:amz" \
--json @- | jq -r

{
  "Status": "RUNNING",
  "EnvironmentId": "abcdefgh-aaaa-bbbb-cccc-dddddddddddd",
  "StatusReason": "",
  "EnvironmentName": "vscode-aws-cloudshell",
  "VpcConfig": {
    "VpcId": "vpc-XYZ",
    "SecurityGroupIds": [
      "sg-123"
    ],
    "SubnetIds": [
      "subnet-ABC"
    ]
  }
}

Delete environment

$ jq --arg env_id 'abcdefgh-aaaa-bbbb-cccc-dddddddddddd' -n '.EnvironmentId = $env_id' | \
curl -s --location --request POST 'https://cloudshell.eu-central-1.amazonaws.com/deleteEnvironment' \
  --header 'Content-Type: application/json' \
  --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \
  -H "x-amz-security-token: $AWS_SESSION_TOKEN" \
  --aws-sigv4 "aws:amz" \
  --json @- | jq -r

{}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment