Creating an S3 bucket through postman.

0

Hi,

I have a Postman collection comprising of a POST to create an S3 bucket. I am able to list S3 buckets.

When I invoke this method I get the following:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>PreconditionFailed</Code>
    <Message>At least one of the pre-conditions you specified did not hold</Message>
    <Condition>Bucket POST must be of the enclosure-type multipart/form-data</Condition>
    <RequestId>J...PZ</RequestId>
    <HostId>I0VPRW...ejkkA=</HostId>
</Error>

I am attaching the Postman exported script (cleaned up to leave the problem call).

{
	"info": {
		"_postman_id": "d914a614-3c17-46e9-9da6-81616e7c42ae",
		"name": "AWs S3 Bucket Ops",
		"description": "This collection creates an S3 Bucket",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "7...2"
	},
	"item": {
			"name": "CreateBucket",
			"request": {
				"method": "POST",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": "<CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"> \r\n    <LocationConstraint>us-east-1</LocationConstraint> \r\n</CreateBucketConfiguration>\r\n"
				},
				"url": {
					"raw": "{{bucketName}}.s3.amazonaws.com",
					"host": [
						"{{bucketName}}",
						"s3",
						"amazonaws",
						"com"
					]
				}
			},
			"response": []
		},
	"auth": {
		"type": "awsv4",
		"awsv4": [
			{
				"key": "service",
				"value": "{{AWSServiceName}}",
				"type": "string"
			},
			{
				"key": "region",
				"value": "{{AWSRegion}}",
				"type": "string"
			},
			{
				"key": "secretKey",
				"value": "{{AWSSecretKey}}",
				"type": "string"
			},
			{
				"key": "accessKey",
				"value": "{{AWSAccessKey}}",
				"type": "string"
			}
		]
	},
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "bucketName",
			"value": "whatever-postman",
			"type": "string"
		}
	]
}

Thanks

profile picture
asked 9 months ago890 views
1 Answer
0

To make it work I did the following:

  • Changed POST into PUT
  • In postman set the body to xml
  • Changed the URL from {{bucketName}}.s3.amazonaws.com to {{bucketName}}.s3.{{AWSRegion}}.amazonaws.com

Status was 200 OK

{
	"info": {
		"_postman_id": "d914a614-3c17-46e9-9da6-81616e7c42ae",
		"name": "AWS S3 Bucket Ops",
		"description": "This collection creates an S3 Bucket",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "74***52"
	},
	"item": {
			"name": "CreateBucket",
			"request": {
				"method": "PUT",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": "<CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"> \r\n    <LocationConstraint>eu-west-3</LocationConstraint> \r\n</CreateBucketConfiguration>\r\n",
					"options": {
						"raw": {
							"language": "xml"
						}
					}
				},
				"url": {
					"raw": "{{bucketName}}.s3.{{AWSRegion}}.amazonaws.com",
					"host": [
						"{{bucketName}}",
						"s3",
						"{{AWSRegion}}",
						"amazonaws",
						"com"
					]
				}
			},
			"response": []

		}
	],
	"auth": {
		"type": "awsv4",
		"awsv4": [
			{
				"key": "service",
				"value": "{{AWSServiceName}}",
				"type": "string"
			},
			{
				"key": "region",
				"value": "{{AWSRegion}}",
				"type": "string"
			},
			{
				"key": "secretKey",
				"value": "{{AWSSecretKey}}",
				"type": "string"
			},
			{
				"key": "accessKey",
				"value": "{{AWSAccessKey}}",
				"type": "string"
			}
		]
	},
	"event": [
		{
			"listen": "prerequest",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		},
		{
			"listen": "test",
			"script": {
				"type": "text/javascript",
				"exec": [
					""
				]
			}
		}
	],
	"variable": [
		{
			"key": "bucketName",
			"value": "whatever-postman",
			"type": "string"
		}
	]
}
profile picture
answered 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions