I'm using serverless Now for a tool invoking AWS via Slack API. The script works fine locally and on server, but I'm having issues in making it work using Now Platform.
This is the error I'm getting:
{"message":"The security token included in the request is invalid."}
There are several questions regarding this, but they don't seem to answer my problem as I see the AWS credentials are correctly configured running cat ~/.aws/credentials
.
I am using AWS Requests Auth:
auth = AWSRequestsAuth(aws_access_key=os.environ['AWS_ACCESS_KEY_ID'],
aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
aws_host='restapiid.execute-api.us-east-1.amazonaws.com',
aws_region='us-east-1',
aws_service='execute-api')
headers = {"Content-Type":"application/json"}
response = requests.post('https://restapiid.execute-api.us-east-1.amazonaws.com/path', auth=auth, headers=headers, data=payload)
As the error is usually 403, I suspect is a Signature expired
issue, but I don't know how to sync Now timestamp with AWS one.
my bad: os.environ['AWS_ACCESS_KEY_ID']
and os.environ['AWS_SECRET_ACCESS_KEY']
are reserved variables in Now platform. When you use them locally with slack API or simple script, it's all fine as it will be using the config file ones, but with Now you need to store and rename them:
now secret add ak "[your aws access key]"
now secret add sk "[your aws secret key]"
now -e AWS_AK=@ak -e AWS_SK=@sk
so then you can use them in you code as
os.environ['AWS_AK']
os.environ['AWS_SK']