Skip to content

Instantly share code, notes, and snippets.

@htnosm
htnosm / aws-cloudshell-cred.sh
Created August 6, 2023 21:54
Get the credentials from AWS CloudShell and output to credential file format.
#!/usr/bin/env bash
# aws-cloudshell-cred.sh
# Get the credentials from AWS CloudShell and output to credential file format.
CONTAINER_CREDENTIALS=$(curl -sSf -H "Authorization: ${AWS_CONTAINER_AUTHORIZATION_TOKEN}" "${AWS_CONTAINER_CREDENTIALS_FULL_URI}")
if [ $? -ne 0 ]; then
echo "failed get container credentials."
exit 1
fi
@htnosm
htnosm / NewRelic-Dashboard-ManageDataAdditionalInformation.json
Last active December 4, 2022 20:38
New Relic manage data additional information dashboard
{
"name": "Manage Data Additional Information",
"description": null,
"permissions": "PUBLIC_READ_WRITE",
"pages": [
{
"name": "Ingest Resource Request Per Minute",
"description": null,
"widgets": [
{
@htnosm
htnosm / _example-tf-unixtime.md
Last active August 20, 2022 08:39
Example of inter-conversion between datetime string and Unixtime in Terraform

example-tf-unixtime

Example of inter-conversion between datetime string and Unixtime in Terraform.

@htnosm
htnosm / echo-awscli.sh
Last active July 3, 2022 04:15
Output aws cli command in bash script
#!/usr/bin/env bash
# Output aws cli command in bash script
# Usage: echo-awscli.sh scriptPath [arg1 arg2 ...]
shopt -s expand_aliases
# mocks
function aws_cli_mock() {
case $@ in
@htnosm
htnosm / aws-codebuild-list-build-durations.sh
Last active January 2, 2022 19:29
List output of AWS CodeBuild duration times.
_PROJECT="Your CodeBuild Project Name"
aws --no-cli-pager codebuild batch-get-builds \
--ids $(aws --no-cli-pager codebuild list-builds-for-project \
--project-name "${_PROJECT}" \
--sort-order DESCENDING --query 'ids[]' --max-items 100 --output text \
| grep -v 'None') \
| jq -r '[
"id", "buildNumber", "startTime", "endTime", "buildStatus",
"buildDuration",
@htnosm
htnosm / rewrite-host-header-index.js
Created September 24, 2021 20:23
Lambda@Edge origin-request trigger to change HTTP Host Header.
'use strict';
exports.handler = (event, context, callback) => {
console.log('event:' + JSON.stringify(event));
// Get contents of request
const request = event.Records[0].cf.request;
// Rewrite
request.headers.host[0].value = '${rewrite_value}';
console.log('request headers:' + JSON.stringify(request.headers));
@htnosm
htnosm / generate-aws-switch-role-bookmark.md
Last active February 26, 2024 07:17
Generate bookmarks HTML based on ~/.aws/config
@htnosm
htnosm / zabbix_export.py
Created November 8, 2020 23:28
Zabbix Export Sample. (Zabbix Ver 4.x)
from pyzabbix import ZabbixAPI
import os
import json
zapi = ZabbixAPI("Your Zabbix URL")
zapi.session.verify = False
zapi.login("Your Zabbix User", "Your Zabbix Password")
print("Connected to Zabbix API Version %s" % zapi.api_version())
output_dir = './var'
@htnosm
htnosm / get-latest-pd-incident.sh
Created April 10, 2020 18:51
PagerDuty の直近インシデントを取得するサンプルスクリプト
#!/bin/bash
# [REST API v2 Overview](https://v2.developer.pagerduty.com/docs/rest-api)
# [API Reference](https://developer.pagerduty.com/api-reference)
_TOKEN="" # REST API Key
_API_VERSION=2
_SERVICE_ID="" # service ID
_TIME_ZONE="Asia/Tokyo"
_LIMIT=100 # Def:25/Max:100
@htnosm
htnosm / sns2slack.py
Last active August 7, 2019 08:29
[Lambda] e.g. Amazon SNS -> Lambda -> Slack
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import boto3
import json
import logging
import os
from base64 import b64decode
from urllib.request import Request, urlopen