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
51 changes: 51 additions & 0 deletions docs/examples/connectors/aws/aws.vjs.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# connector: aws — Comprehensive AWS API integration
#
# Platform connector for Amazon Web Services. Supports multiple operations:
# - S3 (upload, download, list, delete objects)
# - Lambda (invoke functions, list functions)
# - SQS (send messages, receive messages, delete messages)
# - SNS (publish messages, create topics, subscribe)
# - DynamoDB (put item, get item, query, scan)
#
# Uses http-out driver for API calls. AWS requires Signature Version 4 authentication.
# Individual operations use flows that consume from subjects and make direct API calls.
#
# Subjects:
# IN: vx.aws.s3.upload (upload objects to S3)
# IN: vx.aws.lambda.invoke (invoke Lambda functions)
# IN: vx.aws.sqs.send (send messages to SQS)
# IN: vx.aws.sns.publish (publish to SNS topics)
#
# Secrets:
# aws/access_key_id - AWS Access Key ID
# aws/secret_access_key - AWS Secret Access Key
# aws/region - AWS region (e.g., us-east-1)
#
# Rate limits: Varies by service (S3: 3500 PUT/s, Lambda: 1000 concurrent, SQS: unlimited)
# Pagination: Service-specific (S3: marker-based, DynamoDB: LastEvaluatedKey)
#
# Authentication: AWS Signature Version 4 (complex signing process)
# API Version: Service-specific (S3: 2006-03-01, Lambda: 2015-03-31, etc.)
#
# Note: AWS SigV4 requires computing HMAC-SHA256 signatures with request details.
# This connector demonstrates the structure; actual implementation would need
# a signing helper or use AWS SDK wrapped in exec-rpc.

driver "http-out"

# Base configuration for S3 operations
SUBJECT = "vx.aws.s3.upload"
BASE_URL = "https://s3." + secret("aws/region") + ".amazonaws.com"
METHOD = "PUT"

# AWS Signature v4 headers (simplified - actual implementation needs signing)
# In production, this would use an exec-rpc wrapper around AWS SDK
HEADERS = {
"x-amz-date": "${timestamp}",
"x-amz-content-sha256": "${content_hash}",
Authorization: "AWS4-HMAC-SHA256 Credential=" + secret("aws/access_key_id") + "/${date}/" + secret("aws/region") + "/s3/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date, Signature=${signature}",
"Content-Type": "application/octet-stream"
}

# Note: For production use, consider wrapping AWS SDK in exec-rpc connector
# to handle complex authentication and service-specific APIs properly.
22 changes: 22 additions & 0 deletions docs/examples/connectors/aws/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
"ServerSideEncryption": "AES256",
"VersionId": "null",
"Location": "https://my-bucket.s3.us-east-1.amazonaws.com/uploads/document.pdf",
"Bucket": "my-bucket",
"Key": "uploads/document.pdf",
"ResponseMetadata": {
"RequestId": "EXAMPLE123456789",
"HostId": "EXAMPLEHOSTID123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"x-amz-id-2": "EXAMPLEHOSTID123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"x-amz-request-id": "EXAMPLE123456789",
"date": "Mon, 23 Nov 2026 12:00:00 GMT",
"etag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
"server": "AmazonS3",
"content-length": "0"
},
"RetryAttempts": 0
}
}
158 changes: 158 additions & 0 deletions docs/examples/connectors/aws/mock.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#!/usr/bin/env node
// Mock AWS S3 API server for admission testing
// Simulates basic S3 operations (PUT, GET, DELETE objects)

import http from 'http';

const buckets = {
'my-bucket': {}
};

const server = http.createServer((req, res) => {
// CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, HEAD, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Authorization, x-amz-date, x-amz-content-sha256, Content-Type');

if (req.method === 'OPTIONS') {
res.writeHead(200);
res.end();
return;
}

const url = new URL(req.url, `http://${req.headers.host}`);
const pathParts = url.pathname.split('/').filter(p => p);

// PUT /{bucket}/{key} - upload object
if (req.method === 'PUT' && pathParts.length >= 2) {
const bucket = pathParts[0];
const key = pathParts.slice(1).join('/');

if (!buckets[bucket]) {
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist</Message>
<BucketName>${bucket}</BucketName>
</Error>`);
return;
}

let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
buckets[bucket][key] = body;

const etag = '"' + Buffer.from(body).toString('base64').substring(0, 32) + '"';
res.writeHead(200, {
'Content-Type': 'application/xml',
'ETag': etag,
'x-amz-request-id': 'EXAMPLE123456789',
'x-amz-id-2': 'EXAMPLEHOSTID123456789',
'x-amz-server-side-encryption': 'AES256'
});
res.end();
});
return;
}

// GET /{bucket}/{key} - get object
if (req.method === 'GET' && pathParts.length >= 2) {
const bucket = pathParts[0];
const key = pathParts.slice(1).join('/');

if (!buckets[bucket]) {
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist</Message>
</Error>`);
return;
}

if (!buckets[bucket][key]) {
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist</Message>
<Key>${key}</Key>
</Error>`);
return;
}

res.writeHead(200, {
'Content-Type': 'application/octet-stream',
'x-amz-request-id': 'EXAMPLE123456789'
});
res.end(buckets[bucket][key]);
return;
}

// DELETE /{bucket}/{key} - delete object
if (req.method === 'DELETE' && pathParts.length >= 2) {
const bucket = pathParts[0];
const key = pathParts.slice(1).join('/');

if (buckets[bucket] && buckets[bucket][key]) {
delete buckets[bucket][key];
}

res.writeHead(204, {
'x-amz-request-id': 'EXAMPLE123456789',
'x-amz-id-2': 'EXAMPLEHOSTID123456789'
});
res.end();
return;
}

// GET /{bucket} - list objects
if (req.method === 'GET' && pathParts.length === 1) {
const bucket = pathParts[0];

if (!buckets[bucket]) {
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist</Message>
</Error>`);
return;
}

const keys = Object.keys(buckets[bucket]);
const contents = keys.map(key => `
<Contents>
<Key>${key}</Key>
<LastModified>2026-11-23T12:00:00.000Z</LastModified>
<ETag>"${Buffer.from(key).toString('base64').substring(0, 32)}"</ETag>
<Size>${buckets[bucket][key].length}</Size>
<StorageClass>STANDARD</StorageClass>
</Contents>`).join('');

res.writeHead(200, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="UTF-8"?>
<ListBucketResult>
<Name>${bucket}</Name>
<Prefix></Prefix>
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>${contents}
</ListBucketResult>`);
return;
}

// 404 for unknown endpoints
res.writeHead(404, { 'Content-Type': 'application/xml' });
res.end(`<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchKey</Code>
<Message>The specified resource does not exist</Message>
</Error>`);
});

const PORT = process.env.PORT || 8084;
server.listen(PORT, () => {
console.log(`Mock AWS S3 API listening on port ${PORT}`);
});
4 changes: 4 additions & 0 deletions docs/examples/connectors/aws/overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"BASE_URL": "http://localhost:8084",
"SUBJECT": "vx.aws.test.upload"
}
Loading