Search code examples
node.jsamazon-web-servicesaws-sdksegment-analytics

How to authenticate in AWS SDK from segment?


I'm trying to call some AWS services from my segment function. To do that, I need to set the credentials for AWS, but I cannot find the way.

As you can see in the segment documentation, AWS is available. The problems are:

  • I cannot use credential file (I only have one file in the segment funcion and cannot add more)
  • I cannot use environment variables

I have also tried the following:

AWS.config.credentials.accessKeyId = "-";
AWS.config.credentials.secretAccessKey = "-";

That works locally with version 2.949.0 but not with v2.488.0 (the one provided by segment).

Any idea how can I authenticate? I have not found a way to authenticate using javascript code.


Solution

  • Actually, I'm configuring my AWS credentials using

    AWS.config.update({
      region: 'us-east-1',
      accessKeyId: 'ACCESS_KEY',
      secretAccessKey: 'SECRET_KEY',
    });
    

    For example, to use S3 bucket

    import * as AWS from 'aws-sdk';
    
        AWS.config.update({
          region: 'us-east-1',
          accessKeyId: 'ACCESS_KEY',
          secretAccessKey: 'SECRET_KEY',
        });
    
    
    const s3 = new AWS.S3();
    
    // and do some manipulations with s3
    

    I'm not used the segment, but I guess it should work.