Skip to content

Instantly share code, notes, and snippets.

@toddlers
toddlers / mock_requests.py
Created September 1, 2021 14:00 — forked from evansde77/mock_requests.py
Example of mocking requests calls
#!/usr/bin/env python
"""
mocking requests calls
"""
import mock
import unittest
import requests
from requests.exceptions import HTTPError
@toddlers
toddlers / ssh_key.tf
Created June 22, 2021 11:54 — forked from irvingpop/ssh_key.tf
Terraform external data source example - dynamic SSH key generation
# ssh key generator data source expects the below 3 inputs, and produces 3 outputs for use:
# "${data.external.ssh_key_generator.result.public_key}" (contents)
# "${data.external.ssh_key_generator.result.private_key}" (contents)
# "${data.external.ssh_key_generator.result.private_key_file}" (path)
data "external" "ssh_key_generator" {
program = ["bash", "${path.root}/../ssh_key_generator.sh"]
query = {
customer_name = "${var.customer_name}"
customer_group = "${var.customer_group}"
@toddlers
toddlers / s3_upload.sh
Created March 16, 2021 11:02 — forked from tuxfight3r/s3_upload.sh
AWS - Upload files to S3 via curl
#!/bin/bash -x
#Date: 21/7/2017
#Author: Mohan
#Purpose: To upload files to AWS S3 via Curl
#Uploads file at the top level folder by default
#S3 parameters
S3KEY="XXXXXXXXXXX"
S3SECRET="XXXXXXXXXXXXXXXX"
@toddlers
toddlers / all_aws_managed_policies.json
Created March 10, 2021 13:57 — forked from gene1wood/all_aws_managed_policies.json
A list of all AWS managed policies and they're policy documents as well as a short script to generate the list
This file has been truncated, but you can view the full file.
{
"APIGatewayServiceRolePolicy": {
"Arn": "arn:aws:iam::aws:policy/aws-service-role/APIGatewayServiceRolePolicy",
"AttachmentCount": 0,
"CreateDate": "2019-10-22T18:22:01+00:00",
"DefaultVersionId": "v6",
"Document": {
"Statement": [
{
"Action": [
@toddlers
toddlers / gluetags.md
Last active February 15, 2021 10:27
glue tag
aws glue tag-resource --resource-arn arn:aws:glue:eu-central-1:1234567890:job/windowTesting \
--tags-to-add '{"Account Name" : "DNS Dev"}'
$ aws glue get-tags --resource-arn arn:aws:glue:eu-central-1:1234567890:job/windowTesting
{
@toddlers
toddlers / iam.json
Created February 9, 2021 19:03
iam policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": [
"arn:aws:ec2:us-east-2::instance/",
"arn:aws:ec2:us-east-2::network-interface/",
@toddlers
toddlers / main.tf
Last active February 3, 2021 21:04
terraform aws provider 3.23 with role and profile
$ terraform init
Initializing the backend...
Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Installing hashicorp/aws v3.23.0...
- Installed hashicorp/aws v3.23.0 (signed by HashiCorp)
@toddlers
toddlers / index.js
Created February 2, 2021 13:14
nodejs http post
//https://blog.bearer.sh/node-http-request/
//https://nodejs.org/en/knowledge/HTTP/clients/how-to-create-a-HTTP-request/
const http = require("http")
let body = JSON.stringify({
title: "Make a request with Node's http module"
})
let options = {
@toddlers
toddlers / cfn.yml
Created January 23, 2021 14:28
sample api gateway cfn template
AWSTemplateFormatVersion: 2010-09-09
Description: My API Gateway and Lambda function
Parameters:
apiGatewayName:
Type: String
Default: my-api
apiGatewayStageName:
Type: String
AllowedPattern: "[a-z0-9]+"

AWS Cloudformation ApiGateway vs ApiGatewayV2 with Lambda

This shows how to convert a basic REST ApiGateway template to its equivalent HTTP ApiGatewayV2.

The original code before refactoring to ApiGatewayV2 comes from this article

Deployment

Replace MY_PROFILE, MY_REGION and MY_STACK_NAME