Barbara88
Barbara88
Explore posts from servers
CDCloudflare Developers
Created by Barbara88 on 5/14/2024 in #workers-help
Promise not working in JS worker
Hi I have am using the S3 client in a Cloudflare worker
import {GetObjectCommand, ListObjectsV2Command, ListObjectsV2CommandOutput, S3Client} from "@aws-sdk/client-s3";

// Create client
const S3: S3Client = new S3Client({
region: "auto",
endpoint: `https://${accountid}.r2.cloudflarestorage.com`,
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
},
});
import {GetObjectCommand, ListObjectsV2Command, ListObjectsV2CommandOutput, S3Client} from "@aws-sdk/client-s3";

// Create client
const S3: S3Client = new S3Client({
region: "auto",
endpoint: `https://${accountid}.r2.cloudflarestorage.com`,
credentials: {
accessKeyId: env.AWS_ACCESS_KEY_ID,
secretAccessKey: env.AWS_SECRET_ACCESS_KEY,
},
});
If I use await syntax I can log the results from this call in a Worker
const item: ListObjectsV2CommandOutput = await S3.send(new ListObjectsV2Command({Bucket: 'pics'}));
item.Contents.map((item) => {
console.log(item.Key);})
const item: ListObjectsV2CommandOutput = await S3.send(new ListObjectsV2Command({Bucket: 'pics'}));
item.Contents.map((item) => {
console.log(item.Key);})
If I try the same thing using .then() syntax I do not get any logs
S3.send(
new ListObjectsV2Command({Bucket: 'pics'})
).then((item) => {
console.log(item.Contents[0].Key)});
S3.send(
new ListObjectsV2Command({Bucket: 'pics'})
).then((item) => {
console.log(item.Contents[0].Key)});
Can anyone please explain why?
8 replies