Skip to content

Commit 3b19c24

Browse files
committed
BAAS-30361: add amazon third party snippets
1 parent 0f9d8e4 commit 3b19c24

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
exports = async function () {
2+
const {
3+
KinesisClient,
4+
DescribeStreamCommand,
5+
} = require("@aws-sdk/client-kinesis");
6+
const kinesisClient = new KinesisClient({
7+
credentials: {
8+
accessKeyId: context.values.get("awsAccessKeyID"),
9+
secretAccessKey: context.values.get("awsSecretAccessKey"),
10+
},
11+
region: "us-east-1",
12+
maxAttempts: 5,
13+
});
14+
const params = {
15+
StreamName: "myStreamName",
16+
};
17+
18+
// see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/kinesis/ for more commands
19+
const describeStreamCommand = new DescribeStreamCommand(params);
20+
try {
21+
const data = await kinesisClient.send(describeStreamCommand);
22+
return data.StreamDescription.StreamName;
23+
} catch (error) {
24+
return error;
25+
}
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
exports = async function () {
2+
const {
3+
S3Client,
4+
GetObjectCommand,
5+
PutObjectCommand,
6+
} = require("@aws-sdk/client-s3");
7+
const s3Client = new S3Client({
8+
credentials: {
9+
accessKeyId: context.values.get("awsAccessKeyID"),
10+
secretAccessKey: context.values.get("awsSecretAccessKey"),
11+
},
12+
region: "us-east-1",
13+
});
14+
15+
// see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/ for more details
16+
const getObjectCommand = new GetObjectCommand({
17+
Bucket: "myBucketName",
18+
Key: context.values.get("awsBucketKey"),
19+
});
20+
try {
21+
const data = await s3Client.send(getObjectCommand);
22+
return data;
23+
} catch (error) {
24+
return error;
25+
}
26+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
exports = async function () {
2+
const {
3+
S3Client,
4+
GetObjectCommand,
5+
PutObjectCommand,
6+
} = require("@aws-sdk/client-s3");
7+
const s3Client = new S3Client({
8+
credentials: {
9+
accessKeyId: context.values.get("awsAccessKeyID"),
10+
secretAccessKey: context.values.get("awsSecretAccessKey"),
11+
},
12+
region: "us-east-1",
13+
});
14+
15+
// see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/ for more details
16+
const putObjectCommand = new PutObjectCommand({
17+
Bucket: "myBucketName",
18+
Key: context.values.get("awsBucketKey"),
19+
Body: Buffer.from("bucket data"),
20+
});
21+
try {
22+
const data = await s3Client.send(putObjectCommand);
23+
return data !== null && data.ETag !== "";
24+
} catch (error) {
25+
return error;
26+
}
27+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
exports = async function () {
2+
const { SESv2Client, SendEmailCommand } = require("@aws-sdk/client-sesv2");
3+
const sesv2Client = new SESv2Client({
4+
credentials: {
5+
accessKeyId: context.values.get("awsAccessKeyID"),
6+
secretAccessKey: context.values.get("awsSecretAccessKey"),
7+
},
8+
region: "us-east-1",
9+
maxAttempts: 5,
10+
});
11+
12+
// see https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/sesv2/ for more detail
13+
const sendEmailCommand = new SendEmailCommand({
14+
FromEmailAddress: "[email protected]",
15+
Destination: {
16+
ToAddresses: ["[email protected]"],
17+
},
18+
Content: {
19+
Simple: {
20+
Subject: {
21+
Data: "HeLLO SES",
22+
},
23+
Body: {
24+
Text: {
25+
Data: "This is a simple mail",
26+
},
27+
},
28+
},
29+
},
30+
});
31+
32+
try {
33+
const data = await sesv2Client.send(sendEmailCommand);
34+
return data;
35+
} catch (error) {
36+
return error;
37+
}
38+
};

snippets/functions/third-party/manifest.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@
2020
"title": "Using node-fetch dependency",
2121
"snippet": "/nodeFetch.js",
2222
"description": "Making HTTP requests with node-fetch dependency. Atlas App Services does not support v3 of node-fetch, use v2 instead."
23+
},
24+
{
25+
"id": "fdf44706-adbe-4880-87b5-e9c28f6110af",
26+
"title": "Using AWS SES dependency",
27+
"snippets": "/awsSES.js",
28+
"description": "Sending an email with AWS SES. To authenticate with the AWS client, store your AccessKeyID and SecretAccessKey as values. Note: This is using AWS SDK v3."
29+
},
30+
{
31+
"id": "fdf44706-adbe-4880-87b5-e9c28f6110ag",
32+
"title": "Using AWS Kinesis dependency",
33+
"snippets": "/awsKinesis.js",
34+
"description": "Retrieving stream details with AWS Kinesis. To authenticate with the AWS client, store your AccessKeyID and SecretAccessKey as values. Note: This is using AWS SDK v3."
35+
},
36+
{
37+
"id": "fdf44706-adbe-4880-87b5-e9c28f6110aa",
38+
"title": "Retrieving from AWS S3 bucket",
39+
"snippets": "/awsS3GetObject.js",
40+
"description": "Retrieving from AWS S3 bucket with the bucket name and key. To authenticate with the AWS client, store your AccessKeyID and SecretAccessKey as values. Note: This is using AWS SDK v3."
41+
},
42+
{
43+
"id": "fdf44706-adbe-4880-87b5-e9c28f6110ab",
44+
"title": "Putting object in AWS S3 bucket",
45+
"snippets": "/awsS3PutObject.js",
46+
"description": "Putting an object into AWS S3 bucket with the bucket name and key. To authenticate with the AWS client, store your AccessKeyID and SecretAccessKey as values. Note: This is using AWS SDK v3."
2347
}
2448
]
2549
}

0 commit comments

Comments
 (0)