Skip to content

Instantly share code, notes, and snippets.

View 5t33's full-sized avatar

Steven Staley 5t33

View GitHub Profile
@5t33
5t33 / test_server.py
Last active June 29, 2024 19:12
test_server.py
from .server import app
def test_validates_book_no_genre():
book = {
"title": "Cat In The Hat",
"genre": "Historical Fiction"
}
result = app.test_client().post(
"/book",
json=book,
@5t33
5t33 / validate_book_post.py
Last active June 29, 2024 18:58
validate_book_post
@app.route('/book', methods=['POST'])
def create_book():
data = request.get_json()
if not ("title" in data and "author" in data and "genre" in data):
return {"message": "\"title\", \"author\", and \"genre\" are required fields"}, 400
library[data['title']] = data
return library[data['title']], 201
@5t33
5t33 / server.py
Last active June 29, 2024 18:51
flask_boilerplate.py
from flask import (
Flask,
request
)
app = Flask(__name__)
library = {}
@app.route('/book', methods=['POST'])
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: |
This stack holds resources for the primary data pipeline that feeds the my-org event datalake. All user related events runthrough this into Glue.
Parameters:
S3EndpointUrl:
Description: 'Endpoint with which to hit AWS S3. Defaults to usw2.'
Type: 'String'
@5t33
5t33 / cfn-pipe.yaml
Last active July 31, 2023 05:01
cfn-pipe.yaml
Pipe:
Type: AWS::Pipes::Pipe
Properties:
Name: kinesis-to-eventbridge
Description: 'Pipe to connect Kinesis stream to EventBridge event bus'
RoleArn: !GetAtt PipeRole.Arn
Source: !Sub arn:aws:kinesis:us-west-2:${AWS::AccountId}:stream/my-org-app-event-stream-${Environment}
SourceParameters:
FilterCriteria:
Filters:
@5t33
5t33 / cognito-identity-pool.tf
Created July 31, 2023 04:45
cognito-identity-pool.tf
resource "aws_cognito_identity_pool" "users" {
identity_pool_name = "users_identity_pool"
allow_unauthenticated_identities = true
allow_classic_flow = true
cognito_identity_providers {
client_id = aws_cognito_user_pool_client.users.id
provider_name = "cognito-idp.${var.region}.amazonaws.com/${aws_cognito_user_pool.users.id}"
server_side_token_check = false
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobiletargeting:UpdateEndpoint",
"mobiletargeting:PutEvents"
],
"Resource": "arn:aws:mobiletargeting:*:${ACCOUNT_ID}:apps/<your pinpoint app ID>*"
@5t33
5t33 / cognito-identity-role-assume-role-perm.json.tpl
Created July 31, 2023 04:38
cognito-identity-role-assume-role-perm.json.tpl
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "cognito-identity.amazonaws.com"
},
"Action": [
"sts:AssumeRoleWithWebIdentity",
@5t33
5t33 / pinpoint-role-policy.json.tpl
Created July 30, 2023 22:10
pinpoint-role-policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kinesis:PutRecords",
"kinesis:DescribeStream"
],
"Resource": "arn:aws:kinesis:us-west-2:${ACCOUNT_ID}:stream/org-name-app-event-stream-dev"
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sts:AssumeRole"
],
"Principal": {
"Service": "pinpoint.amazonaws.com"