Skip to content

Instantly share code, notes, and snippets.

@mikepietruszka
mikepietruszka / bash
Created January 1, 2020 21:49
get AWS account ID from within an EC2 instance
curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq .accountId | sed 's/"//g'
@mikepietruszka
mikepietruszka / step-function.json
Last active February 24, 2020 15:34
EC2-based Step Functions Worker
{
"Comment": "Simple example that gets status code and puts in SSM Parameter Store",
"StartAt": "process-input",
"States": {
"process-input": {
"Type": "Task",
"Resource": "arn:aws:states:::activity:process-input",
"ResultPath": "$",
"End": true
}
@mikepietruszka
mikepietruszka / get-web-status.py
Last active February 24, 2020 15:36
Sample step function with map processing support: get status code from HTTPS requests and store them in AWS SSM Parameter Store
#!/usr/bin/env python
import boto3
import json
import logging
import requests
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
patch_all()
@mikepietruszka
mikepietruszka / step-function.json
Last active February 24, 2020 13:37
Step Function for storing input payload in a file in S3
{
"StartAt":"Invoke Lambda function",
"States":{
"Invoke Lambda function":{
"Type":"Task",
"Resource":"arn:aws:states:::lambda:invoke",
"Parameters":{
"FunctionName":"arn:aws:lambda:::function:store-payload-to-s3",
"Payload":{
"Input.$":"$"
@mikepietruszka
mikepietruszka / movie-sorter.py
Created April 19, 2020 18:12
Simple movie sorter
#!/usr/bin/env python
'''
Movie sorter
'''
import os
import shutil
import sys
#!/usr/bin/env python
import importlib
import importlib.util
import sys
from pathlib import Path
# Get our command
command = sys.argv[1]
@mikepietruszka
mikepietruszka / apikeys.tf
Last active May 5, 2022 18:46
Google Cloud Platform API Gateway in Terraform
/*
// If you get this error, ensure that your $GOOGLE_APPLICATION_DEFAULTS env
variable is set to a Service Account. Regular cloud identities are not
allowed to hit apikeys.googleapis.com because in the eyes of Google, API keys
are insecure compared to OAuth2 tokens.
│ Error: Error creating Key: failed to create a diff: failed to retrieve Key
| resource: googleapi: Error 403: Your application has authenticated using
| end user credentials from the Google Cloud SDK or Google Cloud Shell which
| are not supported by the apikeys.googleapis.com. We recommend configuring
@mikepietruszka
mikepietruszka / apigateway.tf
Last active May 5, 2022 14:35
Google Cloud Platform API Gateway
# Create an API resource. It will hold our API config and API
# gateway. API gateway will have a URL that we will be able to hit.
resource "google_api_gateway_api" "api" {
provider = google-beta
api_id = "api"
}
# Create an API config that points the API at various
# Cloud Functions, Cloud Run instances, and their
# configurations. The config will be in openapi2-functions.yaml
# openapi2-functions.yaml
# This API once created will be found in APIs & Services console
swagger: '2.0'
info:
title: api-name description-goes-here
description: description-goes-here
version: 1.0.0
schemes:
- https
produces: