I am using the aws-sdk for JS / nodejs to upload files in Angular4 to a S3 bucket.
The upload works fine without any issues if I specify my credentials (accesskeyId, accesskey) when creating the S3 client object.
Issue
I am trying to use ECSCredentials because I do not want to expose my accesskeys anywhere in my code.
My application is running in a ECS Container Instance and is executed with an ECS Task.
I have created an ECS Task role in IAM and attached it to the Task via the Task Role inside my container definitions. (I followed this documentation http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html)
Once the task is running, I am able to log into the container (via ssh) and check if the permissions is working via "curl 169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
This works 100% and outputs my credentials just like the example.
However, I am having a very hard time trying to get this to work with aws-sdk.
In my Angular4 component, I add the SDK like so :
import { ECSCredentials, S3 } from 'aws-sdk';
I create my S3 object like so :
private _s3ClientConfig: S3.ClientConfiguration;
private _s3: S3;
and then create the instance like so :
this._s3ClientConfig = {
credentials: new ECSCredentials({
httpOptions: { timeout: 5000 },
maxRetries: 10,
retryDelayOptions: { base: 200 }}),
region: this._awsConfig.s3BucketRegion,
sslEnabled: true
};
this._s3 = new S3(this._s3ClientConfig);
When I do this, I get the error :
ECSCredentials is not a constructor
I have also tried omitting the "credentials" part, however, then I get the error :
Missing credentials in config
I have also tried creating the S3 client options as type S3.ClientConfiguration or just a normal object, same error persists.
I have followed instructions on another stack overflow question here : How to use ECS credentials with AWS JS SDK , however, no luck, same problems and errors.