in provider-utils/awscloudformation/utils/video-staging.js [375:421]
async function copyFilesToS3(context, options, resourceName, projectType, props) {
const { amplify } = context;
const targetDir = amplify.pathManager.getBackendDirPath();
const targetBucket = amplify.getProjectMeta().providers.awscloudformation.DeploymentBucketName;
const provider = getAWSConfig(context, options);
const aws = await provider.getConfiguredAWSClient(context);
const pluginDir = path.join(`${__dirname}/../..`);
const { stackFolder } = JSON.parse(fs.readFileSync(`${pluginDir}/supported-services.json`))[projectType];
const s3Client = new aws.S3();
const buildDirPath = `${targetDir}/video/${resourceName}/build/${stackFolder}`;
const customDirPath = `${targetDir}/video/${resourceName}/custom/${stackFolder}`;
const fileuploads = fs.readdirSync(buildDirPath);
const promiseFilesToUpload = [];
fileuploads.forEach((filePath) => {
if (filePath === 'LambdaFunctions') {
const relativeFilePath = `${buildDirPath}/${filePath}`;
const foldersToZip = fs.readdirSync(relativeFilePath);
foldersToZip.forEach((lambdaName) => {
if (lambdaName === '.DS_Store') {
return;
}
if (fs.existsSync(`${customDirPath}/${filePath}/${lambdaName}`)) {
promiseFilesToUpload.push(
zipLambdaFunctionsAndPush(context, lambdaName, `${customDirPath}/${filePath}/${lambdaName}`,
customDirPath, s3Client, targetBucket, stackFolder, props.hashes[lambdaName]),
);
} else {
promiseFilesToUpload.push(
zipLambdaFunctionsAndPush(context, lambdaName, `${buildDirPath}/${filePath}/${lambdaName}`,
buildDirPath, s3Client, targetBucket, stackFolder, props.hashes[lambdaName]),
);
}
});
} else if (fs.existsSync(`${customDirPath}/${filePath}`) && !filePath.includes('.zip')) {
promiseFilesToUpload.push(
uploadFile(context, s3Client, targetBucket, customDirPath, filePath, stackFolder),
);
} else if (!filePath.includes('.zip')) {
promiseFilesToUpload.push(
uploadFile(context, s3Client, targetBucket, buildDirPath, filePath, stackFolder),
);
}
});
await Promise.all(promiseFilesToUpload);
}