Skip to content

Instantly share code, notes, and snippets.

View bboure's full-sized avatar
🌍

Benoît Bouré bboure

🌍
View GitHub Profile
@bboure
bboure / datasource.yml
Created March 25, 2023 10:09
AppSync to SNS with Serverless Framework
resolvers:
Mutation.doSomething:
kind: UNIT
request: resolvers/sendMessage.request.vtl
response: resolvers/sendMessage.response.vtl
substitutions:
topicArn: !GetAtt MyTopic.TopicArn
dataSource:
type: HTTP
config:
@bboure
bboure / tempalte.yml
Created December 26, 2021 10:26
Create AWS OIDC identity provider and IAM role for Github Actions
Parameters:
GitHubOrg:
Type: String
RepositoryName:
Type: String
OIDCProviderArn:
Description: Arn for the GitHub OIDC Provider.
Default: ""
Type: String
@bboure
bboure / delete-ssm-by-path.sh
Last active December 11, 2023 11:40
Delete SSM parameters by path prefix
aws ssm get-parameters-by-path --path '/path/to/prams' --recursive \
| jq .Parameters[].Name \
| xargs -L1 -I'{}' aws ssm delete-parameter --name {}
@bboure
bboure / request.vtl
Created April 15, 2021 10:04
AppSync advanced filter
#set($expression = "#PK = :PK")
#set($expressionNames = {"#PK": "PK", "#SK": "SK"})
#set($expressionValues = {":PK": $util.dynamodb.toString("ACCOUNT#${ctx.args.accountId}")})
#if(!$util.isNull($ctx.args.fromDate) && $util.isNull($ctx.args.toDate))
#set($expression = "${expression} and #SK >= :fromDate")
$util.qr($expressionValues.put(":fromDate", $util.dynamodb.toString("TX#${ctx.args.fromDate}")))
#elseif($util.isNull($ctx.args.fromDate) && !$util.isNull($ctx.args.toDate))
#set($expression = "${expression} and #SK <= :toDate")
$util.qr($expressionValues.put(":toDate", $util.dynamodb.toString("TX#${ctx.args.toDate}")))
#elseif(!$util.isNull($ctx.args.fromDate) && !$util.isNull($ctx.args.toDate))
@bboure
bboure / retain.yml
Created April 2, 2021 20:11
5 Ways to Prevent Accidentally Deleting Your CloudFormation Resources
Resources:
MyTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: mytable
@bboure
bboure / read.js
Created April 2, 2021 19:53
DynamoDB Compress large items
//read.js
const AWS = require('aws-sdk');
const { gunzipSync } = require('zlib');
AWS.config.update({ region: 'eu-west-1' });
const dynamoDbClient = new AWS.DynamoDB();
dynamoDbClient.getItem({
"TableName": "blog",
"ReturnConsumedCapacity": "TOTAL",
"Key": {
"author": {
@bboure
bboure / index.d.ts
Created March 31, 2021 15:14
@types/chunk-promise TypeScript
declare module 'chunk-promise' {
type PromiseArray<T> = (() => Promise<T>)[];
type PromiseFlavor = 'PromiseAll' | 'PromiseAllSettled';
type Options<T, F extends PromiseFlavor> = {
concurrent?: number;
sleepMs?: number;
callback?: (
chunkResults: F extends 'PromiseAllSettled'
? PromiseSettledResult<T>[]
: T[],
@bboure
bboure / abort.sh
Last active August 9, 2021 08:55
Stop Step Functions by batch
aws stepfunctions list-executions \
--state-machine-arn [sf-arn] \
--status-filter RUNNING \
--query "executions[*].{executionArn:executionArn}" \
--output text | \
xargs -I {} aws stepfunctions stop-execution \
--execution-arn {}
@bboure
bboure / read.js
Created March 15, 2021 09:51
DynamoDB gzip Large Attribute Values
const AWS = require('aws-sdk');
const { gunzipSync } = require('zlib');
AWS.config.update({ region: 'eu-west-1' });
const dynamoDbClient = new AWS.DynamoDB();
dynamoDbClient.getItem({
"TableName": "blog",
"ReturnConsumedCapacity": "TOTAL",
"Key": {
@bboure
bboure / serverless.yml
Last active December 26, 2020 21:27
appsync-long-cache-demo-serverless.yml
mappingTemplates:
- type: Query
field: wikipedia
kind: PIPELINE
functions:
- fetchFromCache
- fetchWikipedia
- saveToCache
dataSources: