Error uploading object to S3 bucket: ReadRequestBody: unable to initialize upload │ caused by: seek assets/*
See original GitHub issueCommunity Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave “+1” or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
cdktf & Language Versions
cdktf: 0.9.4 Node.js: 16.14.1
Affected Resource(s)
aws_s3_bucket_object
Debug Output
https://gist.github.com/bestickley/faae600e7374e4a89a2563b713cc5c9d
Expected Behavior
Local directory should be uploaded to S3.
Actual Behavior
Error: Error uploading object to S3 bucket (terraform-20220322155938837600000002): ReadRequestBody: unable to initialize upload │ caused by: seek assets/SpaAssets/3594AD6B6CFC5A19C752DFEB9681AE72: The handle is invalid. │ │ with aws_s3_bucket_object.S3BucketObject, │ on cdk.tf.json line 239, in resource.aws_s3_bucket_object.S3BucketObject: │ 239:
Steps to Reproduce
Create a bucket like so:
#createBucket(oai: CloudfrontOriginAccessIdentity, stage: TerraformVariable) {
const staticSiteBucket = new s3.S3Bucket(this, "StaticSiteBucket", {
serverSideEncryptionConfiguration: {
rule: {
applyServerSideEncryptionByDefault: {
sseAlgorithm: "AES256",
},
},
},
});
const bucketToken = Token.asString(staticSiteBucket.arn);
const bucketPolicy = new iam.DataAwsIamPolicyDocument(
this,
"S3BucketIamPolicyDoc",
{
version: "2012-10-17",
statement: [
{
actions: ["s3:*"],
condition: [
{
test: "Bool",
values: ["false"],
variable: "aws:SecureTransport",
},
],
effect: "Deny",
principals: [{ type: "AWS", identifiers: ["*"] }],
resources: [bucketToken, `${bucketToken}/*`],
},
{
actions: ["s3:GetObject"],
effect: "Allow",
resources: [`${bucketToken}/*`],
principals: [{ type: "AWS", identifiers: [oai.iamArn] }],
},
],
}
);
new s3.S3BucketPolicy(this, "S3BucketPolicy", {
bucket: staticSiteBucket.id,
policy: bucketPolicy.json,
});
const assets = new TerraformAsset(this, "SpaAssets", {
path: "../ui/dist",
type: AssetType.DIRECTORY,
});
new S3BucketObject(this, "S3BucketObject", {
bucket: staticSiteBucket.id,
key: "/",
source: assets.path,
});
return staticSiteBucket;
}
Verify cdk.tf.json:
"aws_s3_bucket_object": {
"S3BucketObject": {
"//": {
"metadata": {
"path": "tdmp-em-frontend/S3BucketObject",
"uniqueId": "S3BucketObject"
}
},
"bucket": "${aws_s3_bucket.StaticSiteBucket.id}",
"key": "/${var.stage}",
"source": "assets/SpaAssets/3594AD6B6CFC5A19C752DFEB9681AE72"
}
},
Verify asset exists:
Important Factoids
References
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Resolve errors uploading data to or downloading data from ...
To run the SELECT INTO OUTFILE S3 or LOAD DATA FROM S3 commands using Amazon Aurora, follow the steps below: 1. Create an...
Read more >Upload object to AWS S3 without creating a file using aws-sdk ...
Show what you are trying to upload. s3manager.UploadInput.Body is an io.Reader. Create an io.Reader using bytes.NewReader, strings.NewReader, ...
Read more >aws_s3_bucket_object | Resources | hashicorp/aws
If you prefer to not have Terraform recreate the object, import the object using aws_s3_object . Provides an S3 object resource.
Read more >[S3] RequestError with UploadPart call · Issue #2525 - GitHub
We are using MultipartUpload for uploading some mp3 files to S3.... ... RequestError: send request failed caused by: Put ...
Read more >How to Set up Amazon S3 Upload Provider Plugin for ... - Strapi
You will first set up and configure an S3 storage bucket for your app. Then, you'll create a Strapi App using one of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After some more thought, I’d prefer to let cdktf name my bucket instead of externally defining it as the serverless example, so I’ve come up with this work around:
I know I could get JSON output and use
aws s3 copy
but I’d prefer to keep it in constructs if possible.I think
aws_s3_bucket_object
only uploads a single file, not an entire directory.