AWS Code Sample
Catalog

create_image_no_block_device.go

Creates an Amazon EC2 instance without a block device.

/* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. This file is licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package main import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "fmt" ) func main() { // Load session from shared config sess := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable, })) // Create EC2 service client svc := ec2.New(sess) opts := &ec2.CreateImageInput{ Description: aws.String("image description"), InstanceId: aws.String("i-abcdef12"), Name: aws.String("image name"), BlockDeviceMappings: []*ec2.BlockDeviceMapping{ { DeviceName: aws.String("/dev/sda1"), NoDevice: aws.String(""), }, { DeviceName: aws.String("/dev/sdb"), NoDevice: aws.String(""), }, { DeviceName: aws.String("/dev/sdc"), NoDevice: aws.String(""), }, }, } resp, err := svc.CreateImage(opts) if err != nil { fmt.Println(err) return } fmt.Println("ID: ", resp.ImageId) }

Sample Details

Service: ec2

Last tested: 2018-11-08

Author: Doug-AWS

Type: full-example

On this page: