Skip to content

Instantly share code, notes, and snippets.

View ystoneman's full-sized avatar

Yann Stoneman ystoneman

View GitHub Profile
@ystoneman
ystoneman / SAM.yaml
Last active August 4, 2019 04:57
Stuff you don't need in a serverless.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
# The Serverless Framework outputs the URL automatically,
# minus the `/pets` in Outputs.SpringBootPetStoreApi.Value:
Outputs:
SpringBootPetStoreApi:
Description: URL for application
Value: !Sub 'https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/pets'
Export:
@ystoneman
ystoneman / SAM.yaml
Created August 4, 2019 06:07
SAM.yaml by awslabs for a Spring Boot API
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Example Pet Store API written with SpringBoot with the aws-serverless-java-container library
Globals:
Api:
# API Gateway regional endpoints
EndpointConfiguration: REGIONAL
Resources:
@ystoneman
ystoneman / serverless.yml
Last active August 4, 2019 06:18
Spring Boot Lambda with the serverless framework
service: petstore
provider:
name: aws
runtime: java8
memorySize: 1512
timeout: 60
stage: ${opt:stage,'dev'}
region: ${opt:region, 'us-west-2'}
profile: ${opt:profile, "default"}
@ystoneman
ystoneman / aws-apigateway-find-cache.sh
Created March 20, 2021 15:44
Find all the API Gateway APIs that have cache enabled in a given AWS region.
declare -a arr=($(aws apigateway get-rest-apis --query 'items[*].id' | tr ,[]\" ' '))
for i in "${arr[@]}"
do
declare -a stages=($(aws apigateway get-stages --rest-api-id $i --query 'item[0].stageName' | tr \" ' '))
for j in "${stages[@]}"
do
if $(aws apigateway get-stage --rest-api-id $i --stage-name $j | jq '.cacheClusterEnabled'); then
aws apigateway get-rest-api --rest-api-id $i | jq '.name'
fi
done
@ystoneman
ystoneman / datasync-kms-key-policy.json
Created May 27, 2021 12:53
The minimum permissions to give the DataSync IAM role on your KMS key policy if your S3 bucket is encrypted with that KMS key.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Allow use of the key to the DataSync role",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::012345678910:role/service-role/AWSDataSyncS3BucketAccess-yann-stoneman-dev-storage-us-east-1-012345678910"
]
@ystoneman
ystoneman / cf-snippet.yaml
Last active September 1, 2021 21:23
Snippet of how MasterUser for AWS ElasticSearch is specified in CloudFormation in aws-cdk/packages/@aws-cdk
Resources:
User1:
Type: AWS::IAM::User
Domain1:
Type: AWS::Elasticsearch::Domain
Properties:
AdvancedSecurityOptions:
Enabled: true
InternalUserDatabaseEnabled: false
MasterUserOptions:
@ystoneman
ystoneman / es-signing-http-requests.py
Created September 2, 2021 00:26
Python sample API calls to AWS ElasticSearch using AWS4Auth to sign requests
# Author: https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-request-signing.html#es-request-signing-python
from elasticsearch import Elasticsearch, RequestsHttpConnection
from requests_aws4auth import AWS4Auth
import boto3
host = 'search-testing-mvevysr2i4aen6pqfq5ympghsy.us-east-1.es.amazonaws.com' # For example, my-test-domain.us-east-1.es.amazonaws.com
region = 'us-east-1' # e.g. us-west-1
service = 'es'
@ystoneman
ystoneman / ansible_facts_example_output.json
Created December 28, 2021 17:19
Ansible facts example from docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html
{
"ansible_all_ipv4_addresses": [
"REDACTED IP ADDRESS"
],
"ansible_all_ipv6_addresses": [
"REDACTED IPV6 ADDRESS"
],
"ansible_apparmor": {
"status": "disabled"
},
@ystoneman
ystoneman / sample_metadata_output_amazon_linux_2.json
Created December 28, 2021 18:11
JSON-formatted instance metadata for sample Amazon Linux 2
{
"meta-data": {
"ami-id": "ami-002068ed284fb165b",
"ami-launch-index": 0,
"ami-manifest-path": "(unknown)",
"block-device-mapping": {
"ami": "/dev/xvda",
"root": "/dev/xvda"
},
"events": {
@ystoneman
ystoneman / output-ec2-metadata-to-json.py
Last active December 28, 2021 20:04
Vipin Ajayakumar (bluprince13)'s script, adapted to include /dynamic. The script gets all the output from EC2 instance metadata and outputs it in json format
import requests
import json
metadata_url = 'http://169.254.169.254/latest/'
def expand_tree(url, arr):
output = {}
for item in arr:
new_url = url + item