Colin Gross
2025-10-02
A small issue with IAM when using boto and pysam(htslib)
Provide trimmed down VCFs of BRAVO variants via pre-signed links to objects in S3 bucket.
Boto3 Client used to generate signed urls eventually (6 hours) fails with expired credentials.
Expect Boto3 library to grab credentials from the EC2 instance metadata.
Applications […] that run on the instance can then get automatic temporary security credentials from the instance metadata. You do not have to explicitly get the temporary security credentials.
The S3 plugin allows htslib file functions to communicate with servers that use the AWS S3 protocol.
S3 Plugin docs
#!/bin/sh
instance='http://169.254.169.254'
tok_url="$instance/latest/api/token"
ttl_hdr='X-aws-ec2-metadata-token-ttl-seconds: 10'
creds_url="$instance/latest/meta-data/iam/security-credentials"
key1='aws_access_key_id = \(.AccessKeyId)\n'
key2='aws_secret_access_key = \(.SecretAccessKey)\n'
key3='aws_session_token = \(.Token)\n'
key4='expiry_time = \(.Expiration)\n'
while true; do
token=`curl -X PUT -H "$ttl_hdr" "$tok_url"`
tok_hdr="X-aws-ec2-metadata-token: $token"
role=`curl -H "$tok_hdr" "$creds_url/"`
expires='now'instance='http://169.254.169.254'
creds_url="$instance/latest/meta-data/iam/security-credentials"
And writes them to a file which gets re-read when credentials are expired.
AWS_SHARED_CREDENTIALS_FILE.Avoid putting the credentials for HTSlib in a file that Boto3 will use.
HTS_S3_S3CFGTemplate of BRAVO API systemd service file
End of Slides