Skip to content

Instantly share code, notes, and snippets.

View eoinsha's full-sized avatar

Eoin Shanaghy eoinsha

View GitHub Profile
@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: ''
@eoinsha
eoinsha / sls-function.yml
Created August 7, 2019 15:19
Serverless functions http event
get:
handler: services/checklists/get.main
events:
- http:
path: /{id}
method: get
_ _ _ _ _ _ _
| _| _||_||_ |_ ||_||_|
||_ _| | _||_| ||_| _|
_ _ _ _ _ _ _
| | _| _||_| ||_ ||_||_|
|_||_ _| | ||_| ||_| _|