Skip to content

Instantly share code, notes, and snippets.

View josefaidt's full-sized avatar
🦉

josef josefaidt

🦉
View GitHub Profile
@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 / amplify-cli-symlink-issue-workaround.md
Last active August 11, 2022 18:32
Amplify CLI symlink issue with functions
const pattern = '!(_*|*.d).(js|ts)'
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',
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
const regex = /<(?<tag>[^>]*)>/;
/**
* Verifies whether the string is an HTML string
* @param str string to check
*/
export const isHtmlString = (str: string): boolean => {
// <code>hello world</code> -> true
// hello <code>world</code> -> true
// hello world -> false
@josefaidt
josefaidt / MDXProvider.tsx
Last active January 25, 2023 16:26
RECMA MDX Frontmatter plugin to transform props generated from remark-mdx-frontmatter and feed into wrapper component
import React from 'react';
import { MDXProvider as StockMDXProvider } from '@mdx-js/react';
import type { PropsWithChildren } from 'react';
const wrapper = ({ children, frontmatter }) => {
console.log('mdx page props', { props: { frontmatter } });
return <Page meta={frontmatter}>{children}</Page>;
};
const shortcodes = {
@josefaidt
josefaidt / ambient.d.ts
Last active March 22, 2023 21:11
Amplify CLI command hook helper to auto-commit changes
type HookData = {
amplify: {
environment: {
envName: string
projectPath: string
defaultEditor: string
}
command: string
subCommand: string
argv: string[]
@josefaidt
josefaidt / login.tsx
Last active March 2, 2023 22:42
Sample "login" and "logout" page with Next.js and Amplify UI
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import { useAuthenticator, Authenticator } from '@aws-amplify/ui-react'
export default function LoginPage() {
const { user, route } = useAuthenticator((context) => [
context.user,
context.route,
])
const router = useRouter()
@josefaidt
josefaidt / fetch-aws-credentials.ts
Created January 30, 2024 00:46
fetch-aws-credentials.ts
import { AssumeRoleCommand, STSClient } from '@aws-sdk/client-sts'
export type fetchAwsCredentialsOptions = {
/**
* AWS Region to use
* @default {process.env.AWS_REGION}
*/
region: string
}