From 10fb91652e5269717c472e0958adc4324fed088d Mon Sep 17 00:00:00 2001 From: Chelsey Beck Date: Wed, 14 Feb 2024 19:06:43 -0800 Subject: [PATCH] testing ci connection --- .github/workflows/test-aws-access.yaml | 30 ++++++++++++++++++++++++++ python/list_buckets.py | 22 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/test-aws-access.yaml create mode 100644 python/list_buckets.py diff --git a/.github/workflows/test-aws-access.yaml b/.github/workflows/test-aws-access.yaml new file mode 100644 index 0000000..e7aaf3d --- /dev/null +++ b/.github/workflows/test-aws-access.yaml @@ -0,0 +1,30 @@ +name: List AWS S3 Buckets + +on: [push] + +jobs: + list-buckets: + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + pip install boto3 + + - name: List S3 Buckets + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + run: python list_buckets.py diff --git a/python/list_buckets.py b/python/list_buckets.py new file mode 100644 index 0000000..f9db003 --- /dev/null +++ b/python/list_buckets.py @@ -0,0 +1,22 @@ +import boto3 +import os + +def list_buckets(): + # Create an S3 client using environment variables for credentials + s3 = boto3.client( + 's3', + aws_access_key_id=os.getenv('AWS_ACCESS_KEY_ID'), + aws_secret_access_key=os.getenv('AWS_SECRET_ACCESS_KEY') + ) + + # Call S3 to list current buckets + response = s3.list_buckets() + + # Get a list of all bucket names from the response + buckets = [bucket['Name'] for bucket in response['Buckets']] + + # Print out the bucket list + print("Bucket List: %s" % buckets) + +if __name__ == '__main__': + list_buckets()