Skip to content

Instantly share code, notes, and snippets.

View josefaidt's full-sized avatar
🦉

josef josefaidt

🦉
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
const fn = new lambda.NodejsFunction(this, 'MyFunction', {
entry: fileURLToPath(new URL('./handler.ts', import.meta.url)),
functionName: `my-function`,
bundling: {
minify: true, // minify code, defaults to false
sourceMap: true, // include source map, defaults to false
sourceMapMode: lambda.SourceMapMode.INLINE, // defaults to SourceMapMode.DEFAULT
target: 'esnext',
define: {
'import.meta.vitest': 'undefined',
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 })