Skip to content

Instantly share code, notes, and snippets.

@rtomyj
Last active March 26, 2024 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtomyj/17b41c27600d4ea414a20ca94ffa2e1d to your computer and use it in GitHub Desktop.
Save rtomyj/17b41c27600d4ea414a20ca94ffa2e1d to your computer and use it in GitHub Desktop.
AWS CLI - Useful Commands

AWS CLI

Useful commands and examples for AWS CLI

Custom Compnents

Components are used by Image Builder Recipes in order to setup the software envrioment.

In short, a component installs sofware for an AMI.

Developers can either choose to preset components, use components shared by others, or create their own custom components

List all custom componenets

aws imagebuilder list-components

Get component info

When you have the desired ARN (for the specific component and version) from above command, you can get the info of the component using the following command

aws imagebuilder get-component --component-build-version-arn ${ARN}

Component configuration

In particualr, it is important to be able to get the yaml configuration associated to a particular component/version

aws imagebuilder get-component --query component.data  --component-build-version-arn ${ARN}  --output text

An exmaple of a yaml configuration for a component can be seen below.

The component

  • will update packages installed by yum package manager
  • download docker
  • download docoker-compose (using default version - else calling receipe can specify a version)
  • ensure docker is started as a service - ensures it stays up when users logoff
name: DockerSetup
description: Install docker and docker-compose
schemaVersion: 1.0

parameters:
  - DockerComposeVersion:
      type: string
      default: "2.26.0"
      description: Version of docker compose to install

phases:
  - name: build
    steps:
      - name: UpdateDependencies
        action: ExecuteBash
        inputs:
          commands:
            - yum update -y
      - name: InstallDocker
        action: ExecuteBash
        inputs:
          commands:
            - sudo dnf install docker -y
      - name: InstallDockerCompose
        action: ExecuteBash
        inputs:
          commands:
            - sudo curl -L "https://github.com/docker/compose/releases/download/v{{ DockerComposeVersion }}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
            - sudo chmod +x /usr/local/bin/docker-compose
      - name: RunDockerService
        action: ExecuteBash
        inputs:
          commands:
            - sudo service docker start
            - sudo usermod -a -G docker ec2-user

  - name: validate
    steps:
      - name: ValidateInstall
        action: ExecuteBash
        inputs:
          commands:
            - docker --version

Manipulating Buckets

Create bucket

aws s3 mb s3://${bucket_name}

Copying, moving, syncing files

aws s3 sync ${local_dir} s3://${bucket_name}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment