Tob*_*obi 5 amazon-web-services boto3
我想编写一个脚本来为我启动服务器并进行设置。这应该:
到目前为止,我发现的是如何创建存储桶以及如何创建实例本身:
#@see http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#ec2
aws = boto3.Session(profile_name="myProfile")
s3 = aws.resource('s3', region_name='my-region-1')
bucket = s3.create_bucket(
Bucket='my-cool-bucket',
#...
)
#...
ec2 = aws.resource('ec2', region_name='my-region-1')
ec2.create_instances(
ImageId="my-ami-image-id",
MinCount=1, # I want exactly 1 server
MaxCount=1,
KeyName='my-ssh-key',
SecurityGroupIds=['my-security-group'],
UserData=myStartupScript, # script that will start when server starts
InstanceType='t2.nano',
SubnetId="my-subnet-id",
DisableApiTermination=True,
PrivateIpAddress='10.0.0.1',
#...
)
Run Code Online (Sandbox Code Playgroud)
但是我现在如何为该服务器创建角色并授予该角色访问存储桶的权限?
我找到了创建 InstanceProfile 的方法:
instance_profile = iam.create_instance_profile(
InstanceProfileName='string',
Path='string'
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2607 次 |
| 最近记录: |