Repository: aws/aws-sdk-js (js)

Issue:
Cannot set property 2011-06-15 of #<Object> which has only a getter
Confirm by changing [ ] to [x] below to ensure that it's a bug:
- [x] I've gone through [Developer Guide](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/welcome.html) and [API reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/)
- [x] I've checked [AWS Forums](https://forums.aws.amazon.com) and [StackOverflow](https://stackoverflow.com/questions/tagged/aws-sdk-js) for answers
- [x] I've searched for [previous similar issues](https://github.com/aws/aws-sdk-js/issues) and didn't find any solution
  
**Describe the bug**
***Uncaught TypeError: Cannot set property 2011-06-15 of #<Object> which has only a getter***
when  I tried 
`node dist-tools/browser-builder.js s3,ec2 > aws-sdk-s3-ec2.js
`

and saw this index.html,

```index.html
<!DOCTYPE html>
<html>
  <head>
    <script type="module">
    import AWS from './aws-sdk-s3-ec2.js'
    console.log(AWS)
</script>
  </body>
</html>

```
occurs:

>     aws-sdk-s3-ec2.js:54153 Uncaught TypeError: Cannot set property 2011-06-15 of #<Object> which has only a getter
>     at Object.115.../apis/ec2-2016-11-15.min (aws-sdk-s3-ec2.js:54153)
>     at o (aws-sdk-s3-ec2.js:4)
>     at r (aws-sdk-s3-ec2.js:4)
>     at aws-sdk-s3-ec2.js:4



**Is the issue in the browser/Node.js?**
Browser

**SDK version number**
v2.799.0


Pull request description:
Remove extra sts and cognitoidentity from the browser builder dist
Fixes #3555

When generating specific service, the script always generate extra STS client. Since STS client will already be included by Browserify through the browser credential classes, the extra STS client code is trying to re-assign a property that is already set, and without a setter property, hence the error. This change prevents generating extra sts and cognitoidentity clients that already generated by browserify.

Confirmed the script is only used by the browser builder.

Tested with:
* all services
* sts only
* cognito identity only
* s3 only

##### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->
- [x] changelog is added, `npm run add-change`
- [x] non-code related change (markdown/git settings etc)


Patch:
diff --git a/.changes/next-release/bugfix-Browser-Builder-a41a7d29.json b/.changes/next-release/bugfix-Browser-Builder-a41a7d29.json
new file mode 100644
index 000000000..e904f3e67
--- /dev/null
+++ b/.changes/next-release/bugfix-Browser-Builder-a41a7d29.json
@@ -0,0 +1,5 @@
+{
+  "type": "bugfix",
+  "category": "Browser Builder",
+  "description": "Fixes #3555 Cannot set property 2011-06-15 of #<Object> which has only a getter in strict mode. When generating specific service, the script always generate extra STS client. Since STS client will already be included by Browserify through the browser credential classes, the extra STS client code is trying to re-assign a property that is already set, and without a setter property. This change prevents generating extra sts and cognitoidentity clients that already generated by browserify."
+}
\ No newline at end of file
diff --git a/dist-tools/service-collector.js b/dist-tools/service-collector.js
index 0b09a4141..d05373b6e 100644
--- a/dist-tools/service-collector.js
+++ b/dist-tools/service-collector.js
@@ -143,9 +143,11 @@ function ServiceCollector(services) {
   }
 
   var invalidModules = [];
-  var stsIncluded = false;
   services.split(',').sort().forEach(function(name) {
-    if (name.match(/^sts\b/) || name === 'all') stsIncluded = true;
+    if (['cognitoidentity', 'sts'].indexOf(name) >= 0) {
+      // these service has been included via browser credentials already
+      return;
+    }
     try {
       serviceCode += buildService(name, usingDefaultServicesToggle) + '\n';
     } catch (e) {
@@ -154,10 +156,6 @@ function ServiceCollector(services) {
     }
   });
 
-  if (!stsIncluded) {
-    serviceCode += buildService('sts') + '\n';
-  }
-
   if (invalidModules.length > 0) {
     throw new Error('Missing modules: ' + invalidModules.join(', '));
   }


Test patch:
diff --git a/dist-tools/test/browser-builder.mocha.spec.coffee b/dist-tools/test/browser-builder.mocha.spec.coffee
index 22a48a40f..1035f9036 100644
--- a/dist-tools/test/browser-builder.mocha.spec.coffee
+++ b/dist-tools/test/browser-builder.mocha.spec.coffee
@@ -26,7 +26,6 @@ describe 'ServiceCollector', ->
     add 's3,cloudwatch'
     assertServiceAdded 'S3'
     assertServiceAdded 'CloudWatch'
-    assertServiceAdded 'STS' # STS always added
 
   it 'uses latest service version if version suffix is not supplied', ->
     add 'rds'
@@ -89,6 +88,11 @@ describe 'build', ->
         result = helpers.evalCode(code, data)
       cb(err, result)
 
+  it 'always bundles sts and cognitoidentity clients', -> 
+    buildBundle 's3', null, 'window.AWS', (err, AWS) ->
+      expect(new AWS.STS().api.apiVersion).to.equal(new helpers.AWS.STS().api.apiVersion)
+      expect(new AWS.CognitoIdentity().api.apiVersion).to.equal(new helpers.AWS.CognitoIdentity().api.apiVersion)
+
   it 'defaults to no minification', ->
     buildBundle null, null, 'window.AWS', (err, AWS) ->
       expect(data).to.match(/Copyright Amazon\.com/i)