[awsマイスターシリーズ] aws cli / aws tools for windows powershell

52
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. AWS マイスターシリーズ AWS CLI/AWS Tools for Windows PowerShell 2014.1.15 アマゾン データ サービス ジャパン株式会社 ソリューションアーキテクト 渡邉源太 re:Generate

Upload: amazon-web-services-japan

Post on 26-Jan-2015

217 views

Category:

Technology


12 download

DESCRIPTION

 

TRANSCRIPT

  • 1. re:G ene rate AWS AWS CLI/AWS Tools for Windows PowerShell 2014.1.15 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

2. Agenda ! AWS ! AWS CLI ! AWS Tools for Windows PowerShell ! 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 3. AWS 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 4. AWS AWS Management ConsoleAWS 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 5. APIec2-run-instances ami-b232d0db --instance-count 3 --availability-zone ap-northeast-1a --instance-type m1.smallTokyo ec2-run-instances ami-b232d0db --instance-count 3 --availability-zone ap-northeast-1b --instance-type m1.small 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 6. ! API ! AWS GUICUI SDK AWS 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 7. Put,GetREST AWS SDKSOAP DB 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 8. ! AWSIAM (optional:MFA) 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 9. ! EC2RunInstances RebootInstances IPAllocateAddress http://docs.amazonwebservices.com/AWSEC2/latest/ APIReference/Welcome.html SDK ! API Identity and Access Management(IAM) 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 10. AWS ! Amazon EC2 API Tools Auto Scaling Command Line Tool Amazon RDS Command Line Tool Kit! AWS (CLI) ! AWS Tools for Windows PowerShell 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 11. ! AWS CLI 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 12. AWS CLI ! AWS AWS ! Amazon S3 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 13. 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 14. Mac/Linux! Python 2.6.3 ! pip $ pip install awscli! Amazon Linux AMIAWS CLI 2012 Amazon.com, Inc. and its aliates. All rights reserved. May not be copied, modied or distributed in whole or in part without the express consent of 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. Amazon.com, Inc. 15. Windows ! WindowsCLI http://aws.amazon.com/jp/cli/! AWS CLI 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 16. ! $ aws help! $ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/ bPxRfiCYEXAMPLEKEY Default region name [None]: ap-northeast-1 Default output format [None]: json16 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 17. AWS ! 1: /.aws/config [default] aws_access_key_id=AKIAIOSFODNN7EXAMPLE aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/ bPxRfiCYEXAMPLEKEY aws_security_token=texample123324! 2: AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SECURITY_TOKEN! 3: EC2 IAM 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 18. ! 1: /.aws/config [default] region = ap-northeast-1! 2: AWS_DEFAULT_REGION! 3: --region $ aws sqs list-queues --region ap-northeast-1 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 19. ! json, table, text json ! 1: /.aws/config [default] output = text! 2: AWS_DEFAULT_OUTPUT! 3: --output $ aws ec2 describe-volumes --output table 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 20. ! config [default] aws_access_key_id=AKIAIOSFODNN7EXAMPLE aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/ bPxRfiCYEXAMPLEKEY region=us-east-1 [profile test-user] aws_access_key_id=AKIAI44QH8DHBEXAMPLE aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/ h3yCo8nvbEXAMPLEKEY region=us-west-2! --profile 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 21. EC2:Key Pair ! Key Pair $ aws ec2 create-key-pair --key-name MyKeyPair! Key PairPrivate Key $ aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text > MyKeyPair.pem21 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 22. EC2:Security Group ! Security Group $ aws ec2 create-security-group --group-name MySecurityGroup --description My security group! Security Group $ aws ec2 describe-security-groups --group-names MySecurityGroup! $ aws ec2 authorize-security-group-ingress --group-name MySecurityGroup --protocol tcp --port 22 --cidr 203.0.113.0/2422 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 23. EC2: ! EC2 $ aws ec2 run-instances --image-id ami-0d13700c --count 1 -instance-type t1.micro --key-name MyKeyPair --security-groups MySecurityGroup! EC2 $ aws ec2 stop-instances --instance-ids i-1348636c! EC2 $ aws ec2 start-instances --instance-ids i-1348636c23 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 24. S3 ! S3 ! aws s3 cp:mv:mb:rb:ls: sync! sync S3 $ aws s3 sync MyFolder s3://mybucket/MyFolder --exclude *.tmp 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 25. S31/2 ! S3 $ aws s3 mb s3://MyBucket! $ aws s3 cp MyFile.txt s3://MyBucket/MyFolder! $ aws s3 sync MyFolder s3://MyBucket/MyFolder25 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 26. S3(2/2) ! $ aws s3 rm s3://MyBucket/MyFolder/MyFile.txt! S3 $ aws s3 rb s3://MyBucket26 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 27. SNS ! SNS $ aws sns create-topic --name MyTopic! SNS $ aws sns subscribe --topic-arn arn:aws:sns:apnortheast-1:123456789012:MyTopic --protocol email -notification-endpoint [email protected]! SNS $ aws sns publish --topic-arn arn:aws:sns:apnortheast-1:123456789012:MyTopic --message "Hello World!" 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 28. ! AWS http://aws.amazon.com/jp/cli/! AWS Command Line Interface User Guide http://docs.aws.amazon.com/cli/latest/userguide/cli-chapwelcome.html! CLI Reference http://docs.aws.amazon.com/cli/latest/reference/ 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.28 29. ! AWS Tools for Windows PowerShell 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 30. AWS Tools for Windows PowerShell ! AWS 800 AWS SDK for .NET! ! EC2, S3 http://aws.amazon.com/jp/powershell/30 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 31. AWS SDK for .NET ! AWS SDK for .NET AmazonAWS.NET SDK http://aws.amazon.com/sdkfornet/ .NET Framework 3.5 Visual Studio 2010 2.0.52014/1 C#Visual Basic 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 32. ! AWS Tools for Windows http://aws.amazon.com/powershell/! ! 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 33. 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 34. ! Windows PowerShell for AWS Amazon Web ServicesWindows PowerShell for AWS! PS C:> Initialize-AWSDefaults -AccessKey AKIAIOSFODNN7EXAMPLE -SecretKey wJalrXUtnFEMI/ K7MDENG/bPxRfiCYEXAMPLEKEY -Region ap-northeast-1! PS C:> Get-AWSPowerShellVersion -ListServices34 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 35. AWS ! AWS PS C:> Set-AWSCredentials -AccessKey AKIAIOSFODNN7EXAMPLE -SecretKey wJalrXUtnFEMI/ K7MDENG/bPxRfiCYEXAMPLEKEY StoreAs [email protected]! AWS PS C:> Set-AWSCredentials -StoredCredentials [email protected]! EC2 IAM 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 36. ! PS C:> Get-AWSRegion! -Region PS C:> Get-EC2Image -Region ap-northeast-1! PS C:> Set-DefaultAWSRegion ap-northeast-1! PS C:> Get-DefaultAWSRegion 36 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 37. EC2:Key Pair ! Key Pair PS C:> $myPSKeyPair = New-EC2KeyPair KeyName myPSKeyPair! Private Key PS C:> $myPSKeyPair.KeyMaterial | Out-File -Encoding ascii myPSKeyPair.pem37 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 38. EC2:Security Group1/2 ! Security Group PS C:> New-EC2SecurityGroup -GroupName myPSSecurityGroup GroupDescription AWS Security Group from PowerShell! Security Group PS C:> Get-EC2SecurityGroup -GroupNames myPSSecurityGroup38 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 39. EC2:Security Group2/2 ! Security Group PS C:> $IpPermissions = new-object Amazon.EC2.Model.IpPermission PS C:> $IpPermissions.IpProtocol = "tcp" PS C:> $IpPermissions.FromPort = 3389 PS C:> $IpPermissions.ToPort = 3389 PS C:> $IpPermissions.IpRanges.Add("203.0.113.25/32")! PS C:> Grant-EC2SecurityGroupIngress -GroupName myPSSecurityGroup -IpPermissions $IpPermissions! PS C:> (Get-EC2SecurityGroup -GroupNames myPSSecurityGroup).IpPermissions 39 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 40. EC2:AMI ! AMI PS C:> Get-EC2Image owner amazon, self! Windows AMI PS C:> Get-EC2ImageByName! AMI ID PS C:> Get-EC2ImageByName Names WINDOWS_2012_BASE40 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 41. EC2: ! EC2 PS C:> New-EC2Instance ImageID ami-b1492eb0 MinCount 1 MaxCount 1 KeyName myPSKeyPair SecurityGroup myPSSecurityGroup InstanceType t1.micro! Windows PS C:> Get-EC2PasswordData InstanceId i-7d5ccd78 PemFile myPSKeyPair.pem! EC2 PS C:> Stop-EC2Instance InstanceIds i-7d5ccd78! EC2 PS C:> Start-EC2Instance InstanceIds i-7d5ccd7841 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 42. EC2 Windows: User Data ! User Data PowerShell Add-WindowsFeature Name Web-Server powershell>! User Database64 ! Windows 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 43. S31/2 ! S3 PS C:>New-S3Bucket BucketName mypsbucket! PS C:>Write-S3Object BucketName mypsbucket Key sample.txt File .sample.txt! PS C:>Write-S3Object BucketName mypsbucket Folder . Scripts KeyPrefix SampleScripts43 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 44. S3(2/2) ! PS C:>Remove-S3Object BucketName mypsbucket Key sample.txt! S3 PS C:>Remove-S3Bucket BucketName mypsbucket44 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 45. S3: ! C:Logs1S3 foreach ($i in Get-ChildItem C:Logs) { if ($i.CreationTime -lt ($(Get-Date).AddDays(-7))) { if ($i.Length -gt 0) { Write-S3Object -BucketName mylogbucket -Key Logs/$i File $i.FullName } Remove-Item $i.FullName } } 45 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 46. SNS ! SNS PS C:> New-SNSTopic -Name MyTopic! SNS PS C:> Connect-SNSNotification -TopicArn arn:aws:sns:apnortheast-1:123456789012:MyTopic -Protocol email -Endpoint [email protected]! SNS PS C:> Publish-SNSMessage -TopicArn arn:aws:sns:apnortheast-1:123456789012:MyTopic -Message "Have A Nice Day! 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 47. CloudWatch: ! CloudWatch $dat = New-Object Amazon.CloudWatch.Model.MetricDatum $dat.Timestamp = (Get-Date).ToUniversalTime() $dat.MetricName = "New Posts" $dat.Unit = "Count" $dat.Value = ".50 Write-CWMetricData -Namespace "Usage Metrics" -MetricData $dat 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 48. DynamoDB:1/2 ! PS C:> New-DDBTableSchema! PS C:> Add-DDBKeySchema -KeyName "ForumName" -KeyDataType "S" PS C:> Add-DDBKeySchema -KeyName "Subject" -KeyType "range" KeyDataType "S! PS C:> Add-DDBIndexSchema -IndexName "LastPostIndex" ` -RangeKeyName "LastPostDateTime" ` -RangeKeyDataType "S" ` -ProjectionType "keys_only"! New-DDBTable "Threads" -ReadCapacity 10 -WriteCapacity 548 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 49. DynamoDB:2/2 ! PS C:> New-DDBTableSchema ` | Add-DDBKeySchema -KeyName "ForumName" KeyDataType "S" ` | Add-DDBKeySchema -KeyName "Subject" -KeyType "range" -KeyDataType "S" ` | Add-DDBIndexSchema -IndexName "LastPostIndex" ` -RangeKeyName "LastPostDateTime" ` -RangeKeyDataType "S" ` -ProjectionType "keys_only" ` | New-DDBTable "Threads" -ReadCapacity 10 -WriteCapacity 549 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 50. ! AWS Tools for Windows PowerShell http://aws.amazon.com/jp/powershell/! AWS Tools for Windows PowerShell User Guide http://docs.aws.amazon.com/powershell/latest/userguide/ pstools-welcome.html! AWS Tools for Windows PowerShell Cmdlet Reference http://docs.aws.amazon.com/powershell/latest/reference/ Index.html50 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 51. AWS CLIAWS Tools for Windows PowerShell! ! Windows/Mac/Linux Python 2.6.3! * 30! S3 Windows PowerShell 2.0! * 28! PowerShell*Release Note 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. 52. ! AWSCLIAWS Windows/Mac/Linux ! AWS Tools for Windows PowerShellPowerShell AWS ! 52 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.