I’m following an AWS workshop for SaaS Serverless, however they wrote it with python code and i’m not very good at python so i’m trying to rewrite everything in javascript. It was doing ok until i get to the problem in title.
They use this function to get authentication so i can register my tenant.
import boto3
from aws_requests_auth.aws_auth import AWSRequestsAuth
def get_auth(host, region):
session = boto3.Session()
credentials = session.get_credentials()
auth = AWSRequestsAuth(aws_access_key=credentials.access_key,
aws_secret_access_key=credentials.secret_key,
aws_token=credentials.token,
aws_host=host,
aws_region=region,
aws_service='execute-api')
return auth
The problem is I didn’t find a way of getting credentials unless i hardcode it.
My question is: How can i make this function work the same way in javascript?
EDIT:
This is the workshop i’m following:
https://catalog.us-east-1.prod.workshops.aws/workshops/b0c6ad36-0a4b-45d8-856b-8a64f0ac76bb/en-US
This is the github repo (I’m currently on Lab 2):
https://github.com/aws-samples/aws-serverless-saas-workshop
This is the source of the function i talked about:
https://github.com/aws-samples/aws-serverless-saas-workshop/blob/main/Lab2/server/layers/utils.py
2
Answers
So I did a bit of digging through the source code and found the place where they declare the
AWSRequestsAuth
class here. TL;DR – it’s a class that helps connect to AWS services via Amazon’s signature version 4 signing process.For your problem of getting credentials without hardcoding, I found this guide for Node.js on setting credentials:
It also has further reading to help out with strategies for loading credentials. I know this doesn’t directly answer the question, but I hope this helps!
To use any of the AWS SDKs, always refer to the corresponding Developer Guide. YOu can find a list of supported DEV Guides here:
https://docs.aws.amazon.com/code-library/latest/ug/what-is-code-library.html
See:
As you are interested in the AWS SDK for JavaScript, look at the DEV Guide for this SDK. You can find detailed information abut creds in this topic :
Setting credentials