Skip to content

Instantly share code, notes, and snippets.

@dmost714
dmost714 / apiconfig-cloudformation-template.json
Created May 15, 2023 13:47
Custom resource(s) to add USAGE PLAN and KEYs for API GW REST endpoints
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"env": {
"Type": "String"
},
"apirestapiRootUrl": {
"Type": "String",
"Description": "Input parameter describing RootUrl attribute for api/restapi resource"
},
@dmost714
dmost714 / dynamodbHelpers.ts
Created January 6, 2023 14:55
Batch write to dynamodb, with retry and exponential backoff
import { DynamoDBClient, PutItemCommand, PutRequest } from "@aws-sdk/client-dynamodb"
import { BatchWriteCommandInput, BatchWriteCommandOutput, DynamoDBDocumentClient, QueryCommand, QueryCommandInput, QueryCommandOutput } from "@aws-sdk/lib-dynamodb"
import { BatchWriteCommand } from "@aws-sdk/lib-dynamodb"
import internal from 'node:stream'
// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html
const ddbClient = new DynamoDBClient({})
const marshallOptions = {
@dmost714
dmost714 / AlertNotice-cloudformation-template.json
Created December 11, 2022 20:33
Custom SNS Topic and subscriptions, triggered by Lambda in AWS Amplify
{
"AWSTemplateFormatVersion": "2010-09-09",
"Parameters": {
"env": {
"Type": "String"
}
},
"Resources": {
"SNSTOPIC": {
"Type": "AWS::SNS::Topic",
In the front-end package.json file, add 'amplify:xxx' lines to the script section for each lambda that uses typescript.
Amplify will call those automatically when you build. You can `yarn amplify:nameOfYourLambda` to manually build the lambda.
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"test": "vitest",
"test:ui": "vitest --ui",
"coverage": "vitest run --coverage",
"preview": "vite preview",
"amplify:nameOfYourLambda": "cd amplify/backend/function/nameOfYourLambda/src && yarn && yarn build;cd -",
@dmost714
dmost714 / custom-policies.json
Created August 11, 2022 20:27
Amplify lambda allow email
[
{
"Action": [
"SES:SendEmail"
],
"Resource": [
{
"Fn::Join": [
":",
[
@dmost714
dmost714 / README.md
Last active May 18, 2023 17:53
AWS Amplify: Lambda Url

Amplify Lambda URLs

TL;DR

With AWS Amplify, you can use amplify add api to create REST APIs using API Gatway and Lambdas. However, I wanted to try out the new Lambda Url feature for a simple public webhook.

Steps involved

  1. Make your "Webhook" Lambda
  2. Create a custom reasource "Webhooks".
  3. Give it access to the "Webhook" lambda
@dmost714
dmost714 / export_custom_resource.md
Last active October 21, 2023 14:22
How to expose an Amplify Custom category as an ENVIRONMENT variable in an Amplify Lambda

How to expose an Amplify Custom category as an ENVIRONMENT variable in an Amplify Lambda

These are notes I wrote to myself, but if they help you please leave a note and let me know. And any tips are certainly appreciated.

TL;DR

To reference your custom category resource from your lambda:

  1. amplify add custom to make custom category "XXX"
  2. Add Outputs to XXX-cloudformation-template.json
@dmost714
dmost714 / gist:63d69006edd884bf16ba912404766737
Last active March 29, 2022 18:15
Build a GQL filter to get contacts having any of the passed in tags.
const axios = require('axios')
const gql = require('graphql-tag')
const graphql = require('graphql')
const { print } = graphql
const listContacts = /* GraphQL */ `
query ListContacts(
$filter: ModelContactFilterInput
$limit: Int
$nextToken: String
@dmost714
dmost714 / getCampaign.js
Last active September 21, 2022 15:42
Example calling GQL from Lambda using AppSync
const getCampaign = /* GraphQL */ `
query GetCampaign($id: ID!) {
getCampaign(id: $id) {
id
status
title
postcardDesignId
landingPage
createdAt
updatedAt
@dmost714
dmost714 / App.tsx
Last active April 27, 2023 12:22
I have a SAAS build with AWS Amplify. Unauthenticated users will see the marketing page, which has a 'sign-up/sign-in' button on it. Authenticated users will get the dashboard. Amplify's useAuthenticator hook lets you know if the user is signed in or not. The routing is handled using react-router-v6. Only the / route (index) shows the marketing …
import { Authenticator, View, Image, Text, Heading, useTheme, useAuthenticator } from '@aws-amplify/ui-react'
import { BrowserRouter } from "react-router-dom"
import { Routes, Route } from "react-router-dom"
import AppRoutes from "./AppRoutes"
import MarketingPage from './routes/MarketingPage'
import logoSvg from './logo.svg'
function App() {
const { route, user, signOut } = useAuthenticator(context => [context.route, context.user, context.isPending])