-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from karthik2804/add_examples
- Loading branch information
Showing
73 changed files
with
23,356 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
dist | ||
target | ||
.spin/ | ||
dist.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# AWS S3 Integration | ||
|
||
This example showcases how to connect to and send messages using Amazon S3 with the AWS SDK. | ||
|
||
## Prerequisites | ||
- `spin >=2.6.0` | ||
- | ||
|
||
## Install Dependencies | ||
Install the necessary npm packages: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
## Setup the Example | ||
|
||
1. **Create an AWS Account** | ||
- If you don't have an AWS account, create one at [AWS](https://aws.amazon.com/). | ||
|
||
2. **Create an S3 bucket** | ||
- Go to the [Amazon S3 Console](https://console.aws.amazon.com/s3/). | ||
- Create a new bucket and add files to it. Note down the bucket name. | ||
|
||
3. **Get AWS Credentials** | ||
- Create or obtain your AWS credentials (Access Key ID, Secret Access Key, and a Session Token). | ||
|
||
4. **Configure the Code** | ||
- Copy the region, access key ID, secret access key, session token, and bucket name into the code at `src/index.ts`. | ||
|
||
```typescript | ||
const client = new SQSClient({ | ||
region: "<region>", | ||
credentials: { | ||
accessKeyId: "<accessKeyId>", | ||
secretAccessKey: "<secretAccessKey>", | ||
sessionToken: "<sessionToken>" | ||
}, | ||
}); | ||
|
||
const params = { | ||
Bucket: "<bucketName>" | ||
}; | ||
``` | ||
|
||
## Building and Running the Example | ||
|
||
```bash | ||
spin build | ||
spin up | ||
``` | ||
|
||
Use e.g. curl -v http://127.0.0.1:3000/ to test the endpoint. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "s3", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "npx webpack --mode=production && npx mkdirp target && npx j2w -i dist.js -n spin-http -o target/s3.wasm", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"mkdirp": "^3.0.1", | ||
"ts-loader": "^9.4.1", | ||
"typescript": "^4.8.4", | ||
"webpack": "^5.74.0", | ||
"webpack-cli": "^4.10.0" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-s3": "^3.600.0", | ||
"@fermyon/spin-sdk": "^2.0.0-alpha.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
spin_manifest_version = 2 | ||
|
||
[application] | ||
authors = ["karthik2804 <[email protected]>"] | ||
description = "" | ||
name = "s3" | ||
version = "0.1.0" | ||
|
||
[[trigger.http]] | ||
route = "/..." | ||
component = "s3" | ||
|
||
[component.s3] | ||
source = "target/s3.wasm" | ||
exclude_files = ["**/node_modules"] | ||
allowed_outbound_hosts = ["https://*:*"] | ||
[component.s3.build] | ||
command = "npm run build" | ||
watch = ["src/**/*.ts", "package.json"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ResponseBuilder } from "@fermyon/spin-sdk"; | ||
const { S3Client, ListObjectsV2Command } = require("@aws-sdk/client-s3"); | ||
|
||
const client = new S3Client({ | ||
region: "<>", | ||
credentials: { | ||
accessKeyId: "<>>", | ||
secretAccessKey: "<>", | ||
sessionToken: "<>" | ||
}, | ||
}); | ||
|
||
const params = { | ||
Bucket: "<>" | ||
}; | ||
|
||
const command = new ListObjectsV2Command(params); | ||
|
||
export async function handler(req: Request, res: ResponseBuilder) { | ||
let data | ||
try { | ||
data = await client.send(command); | ||
res.send(JSON.stringify(data.Contents, null, 2)); | ||
} catch (e: any) { | ||
res.status(500) | ||
res.send(`error : ${e.message}`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ResponseBuilder } from "@fermyon/spin-sdk"; | ||
import { handler } from "."; | ||
|
||
//@ts-ignore | ||
addEventListener('fetch', (event: FetchEvent) => { | ||
handleEvent(event); | ||
}); | ||
|
||
async function handleEvent(event: FetchEvent) { | ||
|
||
let resolve: any, reject: any; | ||
let responsePromise = new Promise(async (res, rej) => { | ||
resolve = res; | ||
reject = rej; | ||
}); | ||
//@ts-ignore | ||
event.respondWith(responsePromise); | ||
|
||
let res = new ResponseBuilder(resolve); | ||
|
||
await handler(event.request, res) | ||
} | ||
|
||
// Keep wizer happy during pre-init. Should go away | ||
// oncehttps://github.com/bytecodealliance/ComponentizeJS/issues/114 is resolved | ||
export const incomingHandler = { | ||
handle() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./dist/", | ||
"noImplicitAny": true, | ||
"module": "es6", | ||
"target": "es2020", | ||
"jsx": "react", | ||
"skipLibCheck": true, | ||
"lib": [ | ||
"ES2015", | ||
"WebWorker" | ||
], | ||
"allowJs": true, | ||
"strict": true, | ||
"noImplicitReturns": true, | ||
"moduleResolution": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const path = require('path'); | ||
const SpinSdkPlugin = require("@fermyon/spin-sdk/plugins/webpack") | ||
|
||
module.exports = { | ||
entry: './src/spin.ts', | ||
experiments: { | ||
outputModule: true, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.tsx?$/, | ||
use: 'ts-loader', | ||
exclude: /node_modules/, | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.tsx', '.ts', '.js'], | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, './'), | ||
filename: 'dist.js', | ||
module: true, | ||
library: { | ||
type: "module", | ||
} | ||
}, | ||
plugins: [ | ||
new SpinSdkPlugin() | ||
], | ||
optimization: { | ||
minimize: false | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
dist | ||
target | ||
.spin/ | ||
dist.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# AWS SQS Integration | ||
|
||
This example showcases how to connect to and send messages using Amazon SQS with the AWS SDK. | ||
|
||
## Prerequisites | ||
- `spin >=2.6.0` | ||
- | ||
|
||
## Install Dependencies | ||
Install the necessary npm packages: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
## Setup the Example | ||
|
||
1. **Create an AWS Account** | ||
- If you don't have an AWS account, create one at [AWS](https://aws.amazon.com/). | ||
|
||
2. **Create an SQS Queue** | ||
- Go to the [Amazon SQS Console](https://console.aws.amazon.com/sqs/). | ||
- Create a new SQS queue and note down the Queue URL. | ||
|
||
3. **Get AWS Credentials** | ||
- Create or obtain your AWS credentials (Access Key ID, Secret Access Key, and optionally, a Session Token). | ||
|
||
4. **Configure the Code** | ||
- Copy the region, access key ID, secret access key, session token, and queue URL into the code at `src/index.ts`. | ||
|
||
```typescript | ||
const client = new SQSClient({ | ||
region: "<region>", | ||
credentials: { | ||
accessKeyId: "<accessKeyId>", | ||
secretAccessKey: "<secretAccessKey>", | ||
sessionToken: "<sessionToken>" | ||
}, | ||
}); | ||
|
||
const params = { | ||
MessageBody: 'This is a test message with SQSClient.', | ||
QueueUrl: '<queueUrl>' | ||
}; | ||
|
||
## Building and Running the Example | ||
|
||
```bash | ||
spin build | ||
spin up | ||
``` | ||
|
||
Use e.g. curl -v http://127.0.0.1:3000/ to test the endpoint. |
Oops, something went wrong.