Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.custom
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BUILD_ENV=development
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "yarn spellcheck",
"problemMatcher": ["$eslint-stylish"],
"label": "yarn: spellcheck",
"detail": "Run spellcheck on all MDX files"
}
]
}
Binary file added .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# amplify-docs
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@
"analyze": "ANALYZE=true yarn next-build",
"prebuild": "node src/directory/generateDirectory.mjs && node src/directory/generateFlatDirectory.mjs",
"lint": "next lint"
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
37 changes: 37 additions & 0 deletions package.json.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "amplify-docs",
"packageManager": "yarn@4.5.0",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@aws-amplify/core": "^6.4.2",
"@aws-amplify/ui-react": "^6.5.1",
"@docsearch/css": "^3.6.2",
"@docsearch/react": "^3.6.2",
"@mdx-js/loader": "^3.0.1",
"@mdx-js/react": "^3.0.1",
"@next/mdx": "^14.2.13",
"aws-amplify": "^6.6.2",
"classnames": "^2.5.1",
"next": "^14.0.0",
"next-image-export-optimizer": "^1.15.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rehype-img-size": "^1.0.1",
"rehype-mdx-code-props": "^3.0.1",
"rehype-slug": "^6.0.0",
"remark-gfm": "^4.0.0",
"sass": "^1.79.4"
},
"devDependencies": {
"@types/node": "^20.0.0",
"@types/react": "^18.2.0",
"dotenv": "^16.4.5",
"typescript": "^5.0.0",
"webpack": "^5.95.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,32 @@ export const handler: S3Handler = async (event) => {
</Callout>

Now, when you deploy your backend, these functions will be invoked whenever an object is uploaded or deleted from the bucket.

## More Advanced Triggers

The example listed above demonstrates what is exposed directly in your `storage` definition. Specifically, the use of the `triggers` option when you use `defineStorage`. This method is for simple triggers that always execute on file uploads or file deletions. There are no additional modifications you can make to the triggers defined in this way.

If you want the ability to do something more than simply handle the events `onUpload` and `onDelete` you will have to use `.addEventNotification` in your `backend.ts`. If you use this method, the `triggers` section in your `storage/resource.ts` file should be removed.

Here is an example of how you can add a lambda trigger for an s3 object PUT event. This trigger will execute when a file that has been uploaded to the bucket defined in your `storage/resource.ts` has a matching prefix and suffix as that listed in the function input of `addEventNotification`.

```ts title="amplify/backend.ts"
import { defineBackend } from '@aws-amplify/backend';
import { storage } from './storage/resource';

import { EventType } from 'aws-cdk-lib/aws-s3';
import { LambdaDestination } from 'aws-cdk-lib/aws-s3-notifications';

import { yourLambda } from './functions/yourLambda/resource';

backend.storage.resources.bucket.addEventNotification(
EventType.OBJECT_CREATED_PUT,
new LambdaDestination(backend.yourLambda.resources.lambda),
{
prefix: 'protected/uploads/',
suffix: '-uploadManifest.json',
}
);
```

It's important to note that using this methodology does not require any changes your lambda function. This modification on your `backend.ts` file will create a new `AWS CloudFormation handler for "Custom::S3BucketNotifications" resources (@aws-cdk/aws-s3)` that specifically handles checking the prefix and suffix.
Loading