Skip to content

Instantly share code, notes, and snippets.

View eoinsha's full-sized avatar

Eoin Shanaghy eoinsha

View GitHub Profile
@eoinsha
eoinsha / fetch_lb_logs.py
Created November 1, 2024 05:14
Fetch AWS load balancer recent logs for today to STDOUT
#!/usr/bin/env python3
import os
import sys
from time import strftime
import gzip
import io
import boto3.session
@eoinsha
eoinsha / vscode_cloudshell.md
Last active November 4, 2024 08:46
Running VSCode in AWS CloudShell

VSCode in AWS CloudShell

From time to time, you might want a quick envrionment for doing some dev or troubleshooting within an AWS environment. Since CloudShell now support VPC connections, this is especially useful. Pasting the following commands into CloudShell give you a way to connect from VS Code, edit code, and more.

Install Tools

cd
mkdir -p ~/.local/bin
@eoinsha
eoinsha / tunnel.py
Created April 26, 2024 13:12
Script to aid tunnelling to a Bastion ECS container and run `psql`
#!/usr/bin/env python3
from functools import cache
import os
import sys
from typing import Literal
import json
import click
import boto3
from rich.console import Console
@eoinsha
eoinsha / cloudtrail_table.yaml
Created July 7, 2023 12:58
CloudFormation for CloudTrail Glue Catalog Table
# Working example of a Glue Catalog Data Table for CloudTrail logs that can be used with Athena
CloudTrailGlueTable:
Type: AWS::Glue::Table
Properties:
CatalogId: !Ref AWS::AccountId
DatabaseName: !Ref CloudTrailDatabase
TableInput:
Name: !Sub "${resourcePrefix}_org_cloudtrail"
PartitionKeys:
- Name: account
_ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|
_ _ _ _ _ _ _
| | _| _||_| ||_ ||_||_|
|_||_ _| | ||_| ||_| _|
bucketAccessPoint:
Type: AWS::S3::AccessPoint
Properties:
Bucket: !Ref bucket
Name: ${self:service}-${self:provider.stage}-ap
lambdaAccessPoint:
Type: AWS::S3ObjectLambda::AccessPoint
Properties:
Name: ${self:service}-${self:provider.stage}-lambda-ap
@eoinsha
eoinsha / object-lambda-transform-access.yml
Created March 19, 2021 15:53
object-lambda-transform-access.yml
- Effect: Allow
Action:
- s3-object-lambda:WriteGetObjectResponse
Resource: '*'
- Effect: Allow
Action:
- s3:GetObject
- s3:ListBucket
Resource:
- !GetAtt bucket.Arn
obj_get_ctx = event['getObjectContext']
request_route = obj_get_ctx['outputRoute']
request_token = obj_get_ctx['outputToken']
obj_url = obj_get_ctx['inputS3Url']
requested_url = event['userRequest']['url']
path = Path(urlparse(requested_url).path).relative_to('/')
# First attempt to read directly using the signed URL provided
response = requests.get(obj_url)
resp = {'StatusCode': response.status_code}
@eoinsha
eoinsha / template.yaml
Created March 12, 2020 07:12
EventBridge CloudTrail Data Events and S3 Notification SAM YAML
NotificationFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: handlers/
Handler: notification.handleS3Notification
Runtime: nodejs12.x
Policies:
- Version: '2012-10-17'
Statement:
- Effect: Allow
apiCustomDomain:
Type: AWS::ApiGateway::DomainName
Properties:
CertificateArn: ${self:custom.apiConfig.apiCert}
DomainName: api.sliclists.com
apiCustomDomainPathMappings:
Type: AWS::ApiGateway::BasePathMapping
Properties:
BasePath: ''