How to use ECS task role credentials using SDK SDK in Angular4

I am using aws-sdk for JS / nodejs to upload files in Angular4 to the S3 bucket.

Downloading works fine without any problems if I provide my credentials (accesskeyId, accesskey) when creating the S3 client object.

Question

I am trying to use ECSCredentials because I do not want to disclose my access keys anywhere in my code.

My application runs in an ECS Container Instance and runs using the ECS Task .

I created the ECS task role in IAM and assigned it to the task through the task role in my container definitions. (I followed this documentation http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html )

Once the task is started, I can enter the container (via ssh) and check if the permissions are working with "curl 169.254.170.2 $ AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"

This works 100% and displays my credentials exactly the same as in the example.

However, it’s really hard for me to try to get this to work with aws-sdk.

In my Angular4 component, I add the SDK as follows:

import { ECSCredentials, S3 } from 'aws-sdk';

I create my S3 object as follows:

private _s3ClientConfig: S3.ClientConfiguration;
private _s3: S3;

and then create an instance like this:

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 an error message:

ECSCredentials is not a constructor

I also tried to exclude some of the "credentials", but then I got an error:

 Missing credentials in config

S3 S3.ClientConfiguration , .

: ECS AWS JS SDK, , , .

+4

Source: https://habr.com/ru/post/1683775/


All Articles