This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # 1. Create AWS Lambda function: | |
| # Runtime - Amazon Linux 2023 | |
| # Architecture - arm64 | |
| # 2. Build the Go executable packaged into a zip file | |
| # 3. Upload the zip file | |
| # | |
| all: build package | |
| build: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "context" | |
| "encoding/json" | |
| "errors" | |
| "fmt" | |
| "github.com/aws/aws-lambda-go/lambda" | |
| "log/slog" | |
| "os" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Set up an instance with Amazon Linux 2023 (identical to Lambda Ruby 3.4 environment) | |
| # Install Ruby 3.4.0 (or via RVM) | |
| # Make sure to rename the native extention directory name to match version string | |
| # | |
| all: build package | |
| build: | |
| gem i bigdecimal -Ni ruby/gems/3.4.0 | |
| @if [ -d "ruby/gems/3.4.0/extensions/aarch64-linux/3.4.0+1" ]; then \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Configure logger | |
| NekoLogger.logger = Logger.new($stdout, formatter: proc { |s, d, n, m| "#{s} : #{m}\n" }) | |
| L = NekoLogger.logger | |
| lvl = ENV['NEKO_LOG_LEVEL'] | |
| if String === lvl && ['DEBUG', 'INFO', 'WARN', 'ERROR'].include?(lvl.upcase) | |
| L.level = eval("Logger::#{lvl.upcase}") | |
| end | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Save this at ~/.ssh/config | |
| Host nickname | |
| Hostname 192.168.0.123 | |
| User nick | |
| Port 2222 | |
| IdentityFile ~/.ssh/id_nick | |
| Compression yes | |
| Host * | |
| Compression no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| begin | |
| # do something bad | |
| rescue => e # StandardError by default | |
| puts "Exception class: #{ e.class.name }" | |
| puts "Exception message: #{ e.message }" | |
| puts "Exception backtrace: #{ e.backtrace }" | |
| # Or just: puts "#{e}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'aws-sdk-dynamodb' | |
| # DynamoDB batch write (put) routine | |
| # @param items [Array<Hash>] DynamoDB items to put | |
| # @param table [String] DynamoDB table name | |
| def ddb_batch_put(items, table) | |
| ddb = Aws::DynamoDB::Client.new | |
| batch = items.map { |item| {put_request: {item: item}} if Hash === item } | |
| batch.compact! | |
| puts "Batch write to: #{table}, #{batch.length} items." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Check IP address | |
| ip a | |
| # Check default gateway | |
| ip r | |
| route -n | |
| # Check DNS server | |
| systemd-resolve --status |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'base64' | |
| require 'openssl' | |
| # See: https://www.twilio.com/docs/usage/security#validating-requests | |
| # | |
| # Example of AWS API Gateway (HTTP) + Lambda | |
| def is_twilio_request_valid?(event) | |
| # Create a string that is your URL with the full query string | |
| url = "https://#{event['headers']['host']}#{event['rawPath']}" | |
| # Sort the list of POST variables by the parameter name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version":2, | |
| "path":"/event", | |
| "httpMethod":"GET", | |
| "headers":{ | |
| "Content-Length":"0", | |
| "Host":"abcde12345.execute-api.us-west-2.amazonaws.com", | |
| "User-Agent":"curl/7.54.0", | |
| "X-Amzn-Trace-Id":"Root=1-67891233-abcdef012345678912345678", | |
| "X-Forwarded-For":"192.168.1.23", |
NewerOlder