Skip to content

Instantly share code, notes, and snippets.

View perpil's full-sized avatar
🚀

perpil

🚀
View GitHub Profile
@perpil
perpil / serverless+3.38.0.patch
Created March 28, 2024 20:18
Serverless .mjs support patch. Put in patches/ directory. Use with https://www.npmjs.com/package/patch-package
diff --git a/node_modules/serverless/lib/plugins/aws/invoke-local/index.js b/node_modules/serverless/lib/plugins/aws/invoke-local/index.js
index b227110..6d10a53 100644
--- a/node_modules/serverless/lib/plugins/aws/invoke-local/index.js
+++ b/node_modules/serverless/lib/plugins/aws/invoke-local/index.js
@@ -838,12 +838,15 @@ class AwsInvokeLocal {
if (error.code === 'ERR_REQUIRE_ESM') {
return await require('../../../utils/import-esm')(`${modulePath}.js`);
} else if (error.code === 'MODULE_NOT_FOUND') {
- // Attempt to require handler with `.cjs` extension
- pathToHandler = `${pathToHandler}.cjs`;
@perpil
perpil / coldstart-query
Created March 27, 2024 19:40
Cloudwatch Insights Query for Coldstarts
filter @type = 'REPORT' |
stats sum(ispresent(@initDuration))/count()*100 as `% coldstarts`,
sum((@initDuration+@duration)*ispresent(@initDuration))/sum(ispresent(@initDuration)) as `avg(coldstart)`,
sum(@duration*(1-ispresent(@initDuration)))/sum(1-ispresent(@initDuration)) as `avg(noncoldstart)`
@perpil
perpil / function.js
Created February 7, 2024 19:21
viewer request code for sigv4 signing in a cloudfront function to furl
const crypto = require('crypto');
const querystring = require('querystring');
function hmac(key, string, encoding) {
return crypto
.createHmac('sha256', key)
.update(string, 'utf8')
.digest(encoding);
}
@aws-sdk/util-utf8-browser/dist-es/pureJs.js
@aws-sdk/util-utf8-browser/dist-es/whatwgEncodingApi.js
@aws-sdk/util-utf8-browser/dist-es/index.js
@aws-crypto/crc32/build/index.js
@smithy/util-hex-encoding/dist-es/index.js
@smithy/eventstream-codec/dist-es/Int64.js
@smithy/eventstream-codec/dist-es/HeaderMarshaller.js
@smithy/eventstream-codec/dist-es/splitMessage.js
@smithy/eventstream-codec/dist-es/EventStreamCodec.js
@smithy/eventstream-codec/dist-es/MessageDecoderStream.js
@perpil
perpil / markdownAction.yml
Created January 21, 2024 14:59
Sample of how to emit markdown for speedrun from a GitHub action
name: Print Markdown
on:
workflow_dispatch:
jobs:
print-markdown:
runs-on: ubuntu-latest
steps:
- name: Print Markdown
@perpil
perpil / on-demand.js
Created January 4, 2024 03:58
Lambda logs showing discrepancy in Init Duration between Provisioned Concurrency and On Demand. Also note SecretsManager api call is slower.
2024-01-04T03:38:44.765Z undefined INFO INIT_DETAILS:{
"cpus": [
{
"model": "Neoverse-N1",
"speed": 0,
"times": {
"user": 3240,
"nice": 0,
"sys": 420,
"idle": 938590,

Replace <ddb-metrics-table> with the name of your table (in 2 places) and tweak the start and end time

aws cloudwatch get-metric-data --start-time 2023-10-01T00:00:00Z --end-time 2023-11-01T00:00:00Z --metric-data-queries '[
        {
            "Id": "m1",
            "MetricStat": {
                "Metric": {
                    "Namespace": "AWS/DynamoDB",
                    "MetricName": "ConsumedWriteCapacityUnits",
                    "Dimensions": [
@perpil
perpil / code.html
Last active October 28, 2023 03:30
Boing Boing comments link
<a class="bbs" href="" onclick="if(this.href==location.href){this.href='https://bbs.boingboing.net/t/'+/.*\/(.*)\.html$/.exec(location.pathname)[1];}"> COMMENTS </a>