aws / aws/aws-sam-cli

The "x-amz-security-token" Parameter is Missing from S3 Pre-Signed URL

Open
#2,421 1 comment 0 reactions 0 assignees View on GitHub
area/local/start-api type/bug
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

In my Lambda function I generate a pre-signed URL using the following:
`s3 = boto3.client("s3")`
`s3.generate_presigned_post(Bucket=bucketName, Key=filepath, Fields=None, Conditions=None, ExpiresIn=some_time)`

When deployed, the Lambda function returns the URL (AWSAccessKeyId, policy, and signature) and a `x-amz-security-token` parameter and all works as expected. When using `sam local start-api`, this `x-amz-security-token` parameter appears to be omitted.

The error I get when running locally is: `InvalidToken: The provided token is malformed or otherwise invalid.` Note that an Authorization token is passed to `sam local start-api` in the header.

The only way I was able to get `x-amz-security-token` through was by trying to pass it in the `Fields` parameter of `generate_presigned_post`. Unfortunately, this resulted in the same error as above.

```
# attempt at a work-around
sts = boto3.client('sts')
sess_resp = sts.get_session_token(
DurationSeconds=some_duration
)

fields = {"x-amz-security-token": sess_resp['Credentials']['SessionToken']}
s3.generate_presigned_post(Bucket=bucketName, Key=filepath, Fields=fields, Conditions=None, ExpiresIn=some_time)
```

Any idea what could be happening here?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.