Skip to content

Instantly share code, notes, and snippets.

View josefaidt's full-sized avatar
🦉

josef josefaidt

🦉
View GitHub Profile
const pattern = '!(_*|*.d).(js|ts)'
@josefaidt
josefaidt / amplify-cli-symlink-issue-workaround.md
Last active August 11, 2022 18:32
Amplify CLI symlink issue with functions
@josefaidt
josefaidt / manually-remove-resource-from-amplify-project.md
Created May 13, 2022 19:29
Instructions for surgically removing non-existent resource from local Amplify project

Let's say we've removed a Lambda Layer from the Lambda Console and are no longer able to perform operations using the Amplify CLI.

An error occurred fetching the latest layer version metadata for ""

> amplify remove function
? Choose the resource you would want to remove 10263layer58c94806 (layer)
When you delete a layer version, you can no longer configure functions to use it.
However, any function that already uses the layer version continues to have access to it.
✖ Loading layer data from the cloud...
@josefaidt
josefaidt / lambda-sms.js
Created April 26, 2022 15:18
sends SMS message from Lambda using AWS SDK v3
import { SNSClient, PublishCommand } from '@aws-sdk/client-sns'
const client = new SNSClient()
/**
* Publish a message to a phone number
* @param {string} number - phone number of recipient
* @param {string} [message] - message to send to phone number
* @returns {import('@aws-sdk/client-sns').PublishCommandOutput}
*/
async function publish(number, message) {
@josefaidt
josefaidt / appsync-from-lambda.js
Created April 26, 2022 13:48
Sample AppSync IAM call from Node.js Lambda using AWS SDK v3
import crypto from '@aws-crypto/sha256-js'
import { defaultProvider } from '@aws-sdk/credential-provider-node'
import { SignatureV4 } from '@aws-sdk/signature-v4'
import { HttpRequest } from '@aws-sdk/protocol-http'
import { default as fetch, Request } from 'node-fetch'
const { Sha256 } = crypto
const AWS_REGION = process.env.AWS_REGION || 'us-east-1'
const QUERY_LIST_USERS = /* GraphQL */ `
@josefaidt
josefaidt / get-date-from-epoch.js
Created April 20, 2022 21:38
gets date from epoch
const getDateFromEpoch = epoch => {
let date = new Date(0)
date.setUTCSeconds(epoch)
return date
}
@josefaidt
josefaidt / amplify-init.sh
Last active December 8, 2022 22:31
Minimal Amplify CLI headless init script
#!/bin/bash
set -e
IFS='|'
AMPLIFY_ENVIRONMENT='dev'
AWS_REGION='us-east-1'
AWSCLOUDFORMATIONCONFIG="{\
\"configLevel\":\"project\",\
\"useProfile\":true,\
import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda'
/**
* Invoke our Lambda function with a payload
* @param {Object.<string, any>} payload
* @returns {Promise<import('@aws-sdk/client-lambda').InvokeCommandOutput>}
*/
async function invoke(payload) {
/** @type {import('@aws-sdk/client-lambda').LambdaClient} */
const client = new LambdaClient({ region: process.env.REGION })
@josefaidt
josefaidt / post-checkout
Created November 9, 2021 21:16
Git post-checkout hook to change AWS Amplify environments upon branch checkout
#!/bin/bash
# .git/hooks/post-checkout
# Utility to change AWS Amplify environments on branch checkout
# helper to get path to aws-exports.js
function get_aws_exports_path {
local AMPLIFY_PROJECT_CONFIG_PATH="amplify/.config/project-config.json"
local AMPLIFY_EXPORTS_PATH=$(jq -r '.javascript.config.SourceDir' $AMPLIFY_PROJECT_CONFIG_PATH)
if [[ "$AMPLIFY_EXPORTS_PATH" == */ ]]
// src/pages/_app.js
import { Amplify, Auth } from 'aws-amplify'
import {
AmplifyAuthenticator,
AmplifySignUp,
AmplifySignIn,
AmplifySignOut,
} from '@aws-amplify/ui-react'
import config from '../aws-exports.js'