Continue learning PowerShell to manage AWS S3 today. S3 is much simpler than EC2. S3 is generally used as normal storage, can hold some files that are not too high for I/O requirements, and so on.
His operation is simple, nothing more than creating buckets, deleting buckets, uploading, downloading files, setting access rights and so on; S3 itself can also be made into a simple static web page.
For example, the management interface for AWS
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/83/7B/wKiom1d0jyvwz7GzAAAlCa-bsmc760.png "title=" 1.PNG " alt= "Wkiom1d0jyvwz7gzaaalca-bsmc760.png"/>
Set related properties and so on
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/83/79/wKioL1d0jrTDo7P0AABAnsOqC2s960.png "style=" float: none; "title=" 2.PNG "alt=" Wkiol1d0jrtdo7p0aabansoqc2s960.png "/>
Let's see how PowerShell Implements
Create a new bucket
New-s3bucket-bucketname yliscript-region ap-southeast-2
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/83/7A/wKioL1d0ki_QXAomAAAcYg7POc0867.png "style=" float: none; "title=" 3.PNG "alt=" Wkiol1d0ki_qxaomaaacyg7poc0867.png "/>
Take a look
Get-s3bucket
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/83/7A/wKioL1d0kjax94h3AAAYCMnY-d8895.png "style=" float: none; "title=" 4.PNG "alt=" Wkiol1d0kjax94h3aaaycmny-d8895.png "/>
If you want to remove it, you can remove it and he will pop up the prompt box to confirm
Remove-s3bucket-bucketname Yliscript
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/83/7C/wKiom1d0k4HRmryYAAAtVru8_aY175.png "title=" 5.PNG " alt= "Wkiom1d0k4hrmryyaaatvru8_ay175.png"/>
Here's an example of how to create a static web page on S3
First set his type as static Web page
Write-s3bucketwebsite-bucketname Yliscript-websiteconfiguration_indexdocumentsuffix index.html- Websiteconfiguration_errordocument error.html
On the Web page, verify that the settings are successful. But this time index.html and error.html files are not yet, this need we upload into this bucket inside
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/83/7C/wKiom1d0kkaze0qoAAB9TasWLdY916.png "style=" float: none; "title=" 6.PNG "alt=" Wkiom1d0kkaze0qoaab9taswldy916.png "/>
The command line can also confirm the above settings
Get-s3bucketwebsite-bucketname Yliscript
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/83/7C/wKiom1d0kk3hUvceAAAghWbwA4Y839.png "title=" 7.PNG " Style= "Float:none;" alt= "Wkiom1d0kk3huvceaaaghwbwa4y839.png"/>
Next upload these two files.
Execute the following code, upload the generated two files, access permissions are set to a public readable
$index _html = @ "
Visit the connection and find that the static page has been updated
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/83/7A/wKioL1d0klaxNOcQAAAlbmU_OaM620.png "style=" float: none; "title=" 8.PNG "alt=" Wkiol1d0klaxnocqaaalbmu_oam620.png "/>
If you want to delete this bucket, you need to indicate the deletion of the content, otherwise the error content is not empty, can not be deleted
Remove-s3bucket-bucketname yliscript-deletebucketcontent
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/83/7C/wKiom1d0kl7ST0zYAAArV6RVx-E156.png "style=" float: none; "title=" 9.PNG "alt=" Wkiom1d0kl7st0zyaaarv6rvx-e156.png "/>
The above example has shown that you can upload a file by using the Write-s3object command. When we upload a text file directly, we can assign a value directly to the variable without actually saving it to a local file.
Like what
$x = @ "Line 1 line 2 Line 3" @ write-s3object yuanpicture-key myobject.txt-content $x
Confirm the successful upload
Get-s3object yuanpicture
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/83/7A/wKioL1d0kmnRHHEFAABG-9zLSTw247.png "style=" float: none; "title=" 10.PNG "alt=" Wkiol1d0kmnrhhefaabg-9zlstw247.png "/>
By default, only the uploader has administrative privileges, and if I want other people to access it, I can set sharing permissions.
For example, I specify that the file just uploaded is public readable
Set-s3acl Yuanpicture-key myobject.txt-publicreadonly
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/83/7A/wKioL1d0knTQe7EIAABhSMWghSU737.png "style=" float: none; "title=" 12.PNG "alt=" Wkiol1d0kntqe7eiaabhsmwghsu737.png "/>
So everyone can see it.
Open his connection and see
Get-s3object yuanpicture-key myobject.txt $url = "Https://s3-ap-southeast-2.amazonaws.com/yuanpicture/myobject.txt" Start-process-filepath $url
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/83/7C/wKiom1d0ktnSv4ymAAAieOcRIcs574.png "style=" float: none; "title=" 13.PNG "alt=" Wkiom1d0ktnsv4ymaaaieocrics574.png "/>
If you want to download a file, you can implement it by Read-s3object
For example, I downloaded this file to the current folder, named Test.txt
Read-s3object Yuanpicture-key myobject.txt-file Test.txt
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/83/7B/wKioL1d0kuHxOCyoAAAfsKeJHOg863.png "style=" float: none; "title=" 14.PNG "alt=" Wkiol1d0kuhxocyoaaafskejhog863.png "/>
Look at the content, yes, that's him.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/83/7C/wKiom1d0kunC0WrUAAAHVCaZzkE817.png "style=" float: none; "title=" 15.PNG "alt=" Wkiom1d0kunc0wruaaahvcazzke817.png "/>
The basic operation of the S3 is straightforward, and the next article looks at how to configure the VPC network.
This article is from the "Mapo Tofu" blog, please be sure to keep this source http://beanxyz.blog.51cto.com/5570417/1794496
PowerShell AWS Automation Management (3)