upload/aws: add a sample AWS upload client
This commandline tools uploads a file to S3, as a proof of concept. All options are mandatory. Credentials are only read from the commandline and not from the environment or configuration files. The next step is to add support for importing from S3 to EC2, currently the images we produce cannot be imported as-is, so this requires more research. To try this out: create an S3 bucket, get your credentials and call the tool, passing any value as `key`. Note that if the key already exists, it will be overwritten. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
78ea0e0b6f
commit
7f5c869cd2
6 changed files with 217 additions and 2 deletions
49
cmd/osbuild-upload-aws/main.go
Normal file
49
cmd/osbuild-upload-aws/main.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/osbuild/osbuild-composer/internal/awsupload"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var accessKeyID string
|
||||
var secretAccessKey string
|
||||
var region string
|
||||
var bucketName string
|
||||
var keyName string
|
||||
var filename string
|
||||
var imageName string
|
||||
flag.StringVar(&accessKeyID, "access-key-id", "", "access key ID")
|
||||
flag.StringVar(&secretAccessKey, "secret-access-key", "", "secret access key")
|
||||
flag.StringVar(®ion, "region", "", "target region")
|
||||
flag.StringVar(&bucketName, "bucket", "", "target S3 bucket name")
|
||||
flag.StringVar(&keyName, "key", "", "target S3 key name")
|
||||
flag.StringVar(&filename, "image", "", "image file to upload")
|
||||
flag.StringVar(&imageName, "name", "", "AMI name")
|
||||
flag.Parse()
|
||||
|
||||
a, err := awsupload.New(region, accessKeyID, secretAccessKey)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
uploadOutput, err := a.Upload(filename, bucketName, keyName)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("file uploaded to %s\n", aws.StringValue(&uploadOutput.Location))
|
||||
|
||||
ami, err := a.Register(imageName, bucketName, keyName)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("AMI registered: %s\n", aws.StringValue(ami))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue