awssession

package module
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 4 Imported by: 4

README

awssession - Super simple AWS session generator.

Go Report Card Coverage Status go.dev reference

Example

Simple example of an S3 Get.

package main

import (
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/service/s3"
    "github.com/aws/aws-sdk-go/service/s3/s3manager"
    "github.com/clok/awssession"
    "os"
)

func main() {
    var dstFile *os.File
    dstFile, _ = os.Create(dest)
    
    defer dstFile.Close()

    sess, _ := awssession.New()
    downloader := s3manager.NewDownloader(sess)
    
    _, _ = downloader.Download(dstFile, &s3.GetObjectInput{
        Bucket: aws.String("s3://aBucket"),
        Key:    aws.String("an/object.json"),
    })

    return
}

Development

  1. Fork the clok/awssession repo
  2. Use go >= 1.16
  3. Branch & Code
  4. Run linters 🧹 golangci-lint run
  5. Commit with a Conventional Commit
  6. Open a PR

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() (*session.Session, error)

New establishes a Session to interact with AWS.

Credit to https://github.com/cyberark/summon-aws-secrets/blob/master/main.go for initial implementation.

All clients require a Session. The Session provides the client with shared configuration such as region, endpoint, and credentials. A Session should be shared where possible to take advantage of configuration and credential caching. See the session package for more information.

AWS Go SDK does not currently support automatic fetching of region from ec2metadata. If the region could not be found in an environment variable or a shared config file, create metaSession to fetch the ec2 instance region and pass to the regular Session.

If running on an EC2 instance, the metaClient will be available and we can set the region to match the instance If not on an EC2 instance, the region will remain blank and AWS returns a "MissingRegion: ..." error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL