All files / lib/aws-operations aws-client.js

15.38% Statements 4/26
0% Branches 0/9
0% Functions 0/4
15.38% Lines 4/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                          11x   11x 11x                                                                                         11x            
/* 
 * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 *
 *     http://aws.amazon.com/apache2.0/
 *
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
*/
"use strict";
const AWS = require('aws-sdk')
 
const awsmobileJSConstant = require('../utils/awsmobilejs-constant.js')
const cliConfigManager = require('../utils/cli-config-manager.js')
 
function Mobile(awsDetails){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobileJSConstant.CustomUserAgent})
    AWS.config.update({region: 'us-east-1'}) 
    //mobile api is only available in us-ease-1, but mobile project can be created in other regions
   
    let awsmobileAPIEndpoint = awsmobileJSConstant.AWSMobileAPIEndPoint
    let cliConfig = cliConfigManager.getAWSMobileCLIConfig()
    if(cliConfig && cliConfig.isInDevMode && cliConfig.awsmobileAPIEndpoint){
        awsmobileAPIEndpoint = cliConfig.awsmobileAPIEndpoint
    } 
    const ep = new AWS.Endpoint(awsmobileAPIEndpoint)
 
    return new AWS.Mobile({endpoint: ep})
}
 
function S3(awsDetails, region){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobileJSConstant.CustomUserAgent})
    if(region){
        AWS.config.update({region: region})
    }
 
    return new AWS.S3()
}
 
function Lambda(awsDetails, region){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobileJSConstant.CustomUserAgent})
    if(region){
        AWS.config.update({region: region})
    }
 
    return new AWS.Lambda()
}
 
function CloudFront(awsDetails){
    AWS.config.loadFromPath(awsDetails.info.AWSConfigFilePath)
    AWS.config.update({customUserAgent: awsmobileJSConstant.CustomUserAgent})
 
    return new AWS.CloudFront()
}
 
module.exports = {
    Mobile,
    S3,
    Lambda,
    CloudFront
}