aws-sdk#S3 TypeScript Examples
The following examples show how to use
aws-sdk#S3.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: aws-provider.ts From adminjs-upload with MIT License | 8 votes |
public async upload(file: UploadedFile, key: string): Promise<S3.ManagedUpload.SendData> {
const uploadOptions = { partSize: 5 * 1024 * 1024, queueSize: 10 }
const tmpFile = fs.createReadStream(file.path)
const params: S3.PutObjectRequest = {
Bucket: this.bucket,
Key: key,
Body: tmpFile,
}
if (!this.expires) {
params.ACL = 'public-read'
}
return this.s3.upload(params, uploadOptions).promise()
}
Example #2
Source File: receipt.ts From heimdall with MIT License | 6 votes |
handler = async (event: S3Event) => {
const record = event.Records[0];
console.log(`Received incoming email (key=${record.s3.object.key})`);
const s3 = new S3();
const request = {
Bucket: record.s3.bucket.name,
Key: record.s3.object.key
};
try {
const data = await getRecordData(request, s3);
const email = await simpleParser(data);
const aliases = extractEmailAliases(email);
await processAliases(aliases, email);
await deleteRecord(request, s3);
} catch (err) {
await notifyUserOfError(err);
}
}
Example #3
Source File: aws.ts From erouska-firebase with MIT License | 6 votes |
constructor(private name: string,
key: string,
secret: string) {
this.s3 = new S3({
apiVersion: "2006-03-01",
region: "eu-central-1",
accessKeyId: key,
secretAccessKey: secret
});
}
Example #4
Source File: s3-client.ts From crossfeed with Creative Commons Zero v1.0 Universal | 6 votes |
constructor(isLocal?: boolean) {
this.isLocal =
isLocal ??
(process.env.IS_OFFLINE || process.env.IS_LOCAL ? true : false);
if (this.isLocal) {
this.s3 = new S3({
endpoint: 'http://minio:9000',
s3ForcePathStyle: true
});
} else {
this.s3 = new S3();
}
}
Example #5
Source File: object-storage-service.ts From malagu with MIT License | 6 votes |
protected async doCreateRawCloudService(credentials: Credentials, region: string, clientOptions: ClientOptions, account?: Account): Promise<S3> {
return new S3({
apiVersion: clientOptions.apiVersion,
region,
credentials: {
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.accessKeySecret,
sessionToken: credentials.token
}
});
}
Example #6
Source File: aws-poller.ts From erouska-firebase with MIT License | 6 votes |
async function getFileIfExists(bucket: AWSBucket, file: string, headOnly: boolean = false): Promise<S3.Types.GetObjectOutput | null> {
try {
const params = {
...bucket.key(file)
};
if (headOnly) {
return await bucket.s3.headObject(params).promise();
} else {
return await bucket.s3.getObject(params).promise();
}
} catch (e) {
if ("statusCode" in e && e.statusCode === 404) {
return null;
}
throw e;
}
}
Example #7
Source File: AwsS3EntityProvider.ts From backstage with Apache License 2.0 | 6 votes |
private constructor(
private readonly config: AwsS3Config,
integration: AwsS3Integration,
logger: Logger,
schedule: TaskRunner,
) {
this.logger = logger.child({
target: this.getProviderName(),
});
this.s3 = new S3({
apiVersion: '2006-03-01',
credentials: AwsCredentials.create(
integration.config,
'backstage-aws-s3-provider',
),
endpoint: integration.config.endpoint,
region: this.config.region,
s3ForcePathStyle: integration.config.s3ForcePathStyle,
});
this.scheduleFn = this.createScheduleFn(schedule);
}
Example #8
Source File: AwsS3UrlReader.ts From backstage with Apache License 2.0 | 6 votes |
static factory: ReaderFactory = ({ config, treeResponseFactory }) => {
const integrations = ScmIntegrations.fromConfig(config);
return integrations.awsS3.list().map(integration => {
const credentials = AwsS3UrlReader.buildCredentials(integration);
const s3 = new S3({
apiVersion: '2006-03-01',
credentials,
endpoint: integration.config.endpoint,
s3ForcePathStyle: integration.config.s3ForcePathStyle,
});
const reader = new AwsS3UrlReader(integration, {
s3,
treeResponseFactory,
});
const predicate = (url: URL) =>
url.host.endsWith(integration.config.host);
return { reader, predicate };
});
};
Example #9
Source File: s3matcher.ts From amplify-codegen with Apache License 2.0 | 6 votes |
toBeAS3Bucket = async (bucketName: string) => {
const s3 = new S3();
let pass: boolean;
try {
await s3.headBucket({ Bucket: bucketName }).promise();
pass = true;
} catch (e) {
pass = false;
}
const messageStr = pass ? `expected S3 bucket ${bucketName} exist` : `expected S3 bucket ${bucketName} does exist`;
return {
message: () => messageStr,
pass,
};
}
Example #10
Source File: sdk-calls.ts From amplify-codegen with Apache License 2.0 | 6 votes |
bucketNotExists = async (bucket: string) => {
const s3 = new S3();
const params = {
Bucket: bucket,
$waiter: { maxAttempts: 10, delay: 30 },
};
try {
await s3.waitFor('bucketNotExists', params).promise();
return true;
} catch (error) {
if (error.statusCode === 200) {
return false;
}
throw error;
}
}
Example #11
Source File: aws-provider.ts From adminjs-upload with MIT License | 6 votes |
constructor(options: AWSOptions) {
super(options.bucket)
let AWS_S3: typeof S3
try {
// eslint-disable-next-line
const AWS = require('aws-sdk')
AWS_S3 = AWS.S3
} catch (error) {
throw new Error(ERROR_MESSAGES.NO_AWS_SDK)
}
this.expires = options.expires ?? DAY_IN_MINUTES
this.s3 = new AWS_S3(options)
}
Example #12
Source File: aws-s3-file-storage.ts From advanced-node with GNU General Public License v3.0 | 6 votes |
async upload ({ fileName, file }: UploadFile.Input): Promise<UploadFile.Output> {
await new S3().putObject({
Bucket: this.bucket,
Key: fileName,
Body: file,
ACL: 'public-read'
}).promise()
return `https://${this.bucket}.s3.amazonaws.com/${encodeURIComponent(fileName)}`
}
Example #13
Source File: clean-objects.lambda.ts From cloudstructs with Apache License 2.0 | 5 votes |
s3 = new S3()
Example #14
Source File: S3StorageProvider.ts From hotseat-api with MIT License | 5 votes |
private client: S3;
Example #15
Source File: redirect.edge-lambda.ts From cloudstructs with Apache License 2.0 | 5 votes |
s3 = new S3({ apiVersion: '2006-03-01' })
Example #16
Source File: receipt.ts From heimdall with MIT License | 5 votes |
deleteRecord = async (
request: S3.DeleteObjectRequest,
s3: S3
): Promise<void> => {
console.log("Deleting email from S3 storage");
await s3.deleteObject(request).promise();
console.log("Deleted email from S3 storage");
}
Example #17
Source File: shortener.lambda.ts From cloudstructs with Apache License 2.0 | 5 votes |
s3 = new S3({ apiVersion: '2006-03-01' })
Example #18
Source File: receipt.ts From heimdall with MIT License | 5 votes |
getRecordData = async (
request: S3.GetObjectRequest,
s3: S3
): Promise<Buffer> => {
console.log("Fetching email from S3 storage");
return (await s3.getObject(request).promise()).Body as Buffer;
}
Example #19
Source File: S3StorageProvider.ts From gobarber-project with MIT License | 5 votes |
constructor() {
this.client = new aws.S3({
region: 'us-east-1',
});
}
Example #20
Source File: S3StorageProvider.ts From gobarber-project with MIT License | 5 votes |
private client: S3;
Example #21
Source File: S3StorageProvider.ts From GoBarber with MIT License | 5 votes |
constructor() {
this.client = new aws.S3({
region: 'us-east-1',
});
}
Example #22
Source File: S3StorageProvider.ts From GoBarber with MIT License | 5 votes |
private client: S3;
Example #23
Source File: aws.ts From erouska-firebase with MIT License | 5 votes |
public s3: S3;
Example #24
Source File: aws-s3-file-storage.ts From advanced-node with GNU General Public License v3.0 | 5 votes |
async delete ({ fileName }: DeleteFile.Input): Promise<void> {
await new S3().deleteObject({
Bucket: this.bucket,
Key: fileName
}).promise()
}
Example #25
Source File: s3-client.ts From crossfeed with Creative Commons Zero v1.0 Universal | 5 votes |
s3: S3;
Example #26
Source File: AwsS3EntityProvider.ts From backstage with Apache License 2.0 | 5 votes |
private readonly s3: S3;
Example #27
Source File: AwsS3UrlReader.ts From backstage with Apache License 2.0 | 5 votes |
constructor(
private readonly integration: AwsS3Integration,
private readonly deps: {
s3: S3;
treeResponseFactory: ReadTreeResponseFactory;
},
) {}
Example #28
Source File: sdk-calls.ts From amplify-codegen with Apache License 2.0 | 5 votes |
deleteS3Bucket = async (bucket: string) => {
const s3 = new S3();
let continuationToken: Required<Pick<S3.ListObjectVersionsOutput, 'KeyMarker' | 'VersionIdMarker'>> = undefined;
const objectKeyAndVersion = <S3.ObjectIdentifier[]>[];
let truncated = false;
do {
const results = await s3
.listObjectVersions({
Bucket: bucket,
...continuationToken,
})
.promise();
results.Versions?.forEach(({ Key, VersionId }) => {
objectKeyAndVersion.push({ Key, VersionId });
});
results.DeleteMarkers?.forEach(({ Key, VersionId }) => {
objectKeyAndVersion.push({ Key, VersionId });
});
continuationToken = { KeyMarker: results.NextKeyMarker, VersionIdMarker: results.NextVersionIdMarker };
truncated = results.IsTruncated;
} while (truncated);
const chunkedResult = _.chunk(objectKeyAndVersion, 1000);
const deleteReq = chunkedResult
.map(r => {
return {
Bucket: bucket,
Delete: {
Objects: r,
Quiet: true,
},
};
})
.map(delParams => s3.deleteObjects(delParams).promise());
await Promise.all(deleteReq);
await s3
.deleteBucket({
Bucket: bucket,
})
.promise();
await bucketNotExists(bucket);
}
Example #29
Source File: sdk-calls.ts From amplify-codegen with Apache License 2.0 | 5 votes |
checkIfBucketExists = async (bucketName: string, region: string) => {
const service = new S3({ region });
return await service.headBucket({ Bucket: bucketName }).promise();
}