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
const { CopyObjectCommand, S3Client } = require('@aws-sdk/s3-client'); | |
const client = new S3Client({}); | |
const moveFile = async (sourceKey, destBucket, destKey) => { | |
const params = { | |
Bucket: destBucket, | |
Key: destKey, | |
CopySource: sourceKey, | |
}; |
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
import { Stack, StackProps, Duration } from 'aws-cdk-lib'; | |
import { Construct } from 'constructs'; | |
import * as IAM from 'aws-cdk-lib/aws-iam'; | |
import * as sqs from 'aws-cdk-lib/aws-sqs'; | |
import * as ApiGW from 'aws-cdk-lib/aws-apigateway'; | |
export class AwsSqsDirectIntegrationStack extends Stack { | |
constructor(scope: Construct, id: string, props?: StackProps) { | |
super(scope, id, props); |
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
const { RekognitionClient, DetectLabelsCommand } = require('@aws-sdk/client-rekognition'); | |
const client = new RekognitionClient({}); | |
const getLabels = async (picture) => { | |
const params = { | |
Image: { | |
Bytes: picture, | |
}, | |
MaxLabels: 20, |
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
import { SNSClient, PublishCommand } from '@aws-sdk/client-sns'; | |
const client = new SNSClient({}); | |
const handler = async (event) => { | |
if (!event.body) { | |
return { message: 'Body not found' } | |
} | |
const { numberPhone, text } = JSON.parse(event.body); | |
const params = { |
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
const uploadFile = async () => { | |
const params = { | |
Bucket: process.env.BUCKET, | |
Key: 'file-upload.txt', | |
Body: 'hello world', | |
}; | |
const upload = new Upload({ | |
client, | |
params, |
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
const putFile = async () => { | |
const params = { | |
Bucket: process.env.BUCKET, | |
Key: 'file.txt', | |
Body: 'hello world', | |
}; | |
return client.send(new PutObjectCommand(params)); | |
}; |
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
module.exports.index = async (event) => { | |
const failedIds = event.Records.reduce((acc, item, index) => { | |
// half of records fail | |
if (index % 2 === 0) { | |
acc.push({ itemIdentifier: item.messageId }); | |
} | |
return acc; | |
}, []); |
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
const { SSMClient, GetParameterCommand } = require('@aws-sdk/client-ssm'); | |
const AWSXRay = require('aws-xray-sdk'); | |
// code outside the handler | |
const client = AWSXRay.captureAWSv3Client(new SSMClient({})); | |
let value; | |
module.exports.handler = async () => { | |
// check if values is cached |
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
const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3'); | |
const client = new S3Client({}); | |
const streamToString = (stream) => new Promise((resolve, reject) => { | |
const chunks = []; | |
stream.on('data', (chunk) => chunks.push(chunk)); | |
stream.on('error', reject); | |
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); | |
}); |
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
const streamToString = (stream) => new Promise((resolve, reject) => { | |
const chunks = []; | |
stream.on('data', (chunk) => chunks.push(chunk)); | |
stream.on('error', reject); | |
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); | |
}); |