Skip to content

Instantly share code, notes, and snippets.

You are now aware that you are breathing

Brian LeRoux brianleroux

You are now aware that you are breathing
View GitHub Profile
brianleroux / fun.js
Created Jun 14, 2022
example of runtime resource discovery built into architect
View fun.js
import arc from '@architect/functions'
// send an event to the SNS topic named 'ping'
// … under the hood the ARN is arn:aws:sns:us-west-2:818138539153:appname-ping-Q1C4HOR7RT2H:6bd207a6-4aaf-4015-bad4-a30adf7944f
name: 'ping',
payload: { pingID: }
// read from the db table named 'pings'
View aws.cjs
let aws = require('aws-sdk')
module.exports = {
CloudFormation: aws.CloudFormation,
ApiGatewayV2: aws.ApiGatewayV2,
ACM: aws.ACM,
Route53: aws.Route53,
View output.txt
> @architect/architect@9.5.1 test:unit
> cross-env tape 'test/unit/**/*-test.js'
TAP version 13
# Core Architect packages and necessary CLI interfaces are present
ok 1 create found
ok 2 create CLI found
ok 3 deploy found
ok 4 deploy CLI found
brianleroux / .arc-config
Created Sep 15, 2020
examle .arc-config with multiple policies
View .arc-config
runtime python3.7
memory 256
timeout 3
concurrency 1
View sam-ws-fun.json
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "Exported by architect/package@2.0.0-RC.0 on 2020-07-13T17:10:57.465Z",
"Resources": {
"HTTP": {
"Type": "AWS::Serverless::HttpApi",
"Properties": {
"StageName": "$default",
"DefinitionBody": {
View foo.js
// sign up save the data by creating a dynamic index..
await begin.set([
{table: `users`, key: userID, email, name, etc},
{table: `user-${ email }`, key: userID, email, name, etc}
brianleroux / .arc-env
Created Mar 23, 2020
working local with env vars
View .arc-env
# ensure this file is in your .gitignore
# example .arc-env
MYVAR asdfasdf
MYVAR2 blah
MYVAR2 foo

What's the best way to invoke another function? (or get it's ARN)

reccomend using @events or @queues for 'background tasks' (events are SNS topics, unordered ans async…queues are SQS fifo queues)

is it safe to put await arc.tables() outside the event handler of a function?

you can, it will make a one time call to SSM to resolve generated table names with the names defined .arc but generally I'd reccomend keeping things deterministic as possible and doing it in the main function body

how does specifying a ddb trigger look?

View demo.js
// get the client
let data = await arc.tables()
// get the generated table names
let tables = await data.reflect()
// use the document client directly
data._doc.batchGet({TableName: tables.mytable ...})
View example-o-pagination-ddb.js
let aws = require('aws-sdk')
let region = 'us-west-1'
let db = new aws.DynamoDB.DocumentClient({region})
TableName: 'begin-production-builds',
IndexName: 'begin-production-builds-appID_env-ts-index',
KeyConditionExpression: '#appID_env = :appID_env',
ExpressionAttributeNames: {
'#appID_env': 'appID_env'