Skip to content
This repository was archived by the owner on Dec 2, 2020. It is now read-only.

Commit 933e1b4

Browse files
committed
Add credentials profile command line option
Fixes #18
1 parent 9c93fd9 commit 933e1b4

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ USAGE:
3333
GLOBAL OPTIONS:
3434
--image value, -i value Name of the source container image. For example, 'my-docker-image:latest'. The Docker image must be pulled locally already.
3535
--region value, -r value AWS region (default: "us-east-1")
36+
--profile value, -p value AWS credentials profile. Credentials will default to the same chain as the AWS CLI: environment variables, default profile, container credentials, EC2 instance credentials
3637
--output-directory value, -o value Destination directory for command output (default: "./output")
3738
--layer-namespace value, -n value Prefix for the layers published to Lambda (default: "img2lambda")
3839
--dry-run, -d Conduct a dry-run: Repackage the image, but only write the Lambda layers to local disk (do not publish to Lambda)

img2lambda/cli/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func createApp() (*cli.App, *types.CmdOptions) {
4242
Value: "us-east-1",
4343
Destination: &opts.Region,
4444
},
45+
cli.StringFlag{
46+
Name: "profile, p",
47+
Usage: "AWS credentials profile. Credentials will default to the same chain as the AWS CLI: environment variables, default profile, container credentials, EC2 instance credentials",
48+
Destination: &opts.Profile,
49+
},
4550
cli.StringFlag{
4651
Name: "output-directory, o",
4752
Usage: "Destination directory for command output",

img2lambda/clients/clients.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ var userAgentHandler = request.NamedHandler{
1515
Fn: request.MakeAddToUserAgentHandler("aws-lambda-container-image-converter", version.Version),
1616
}
1717

18-
func NewLambdaClient(region string) *lambda.Lambda {
19-
sess := session.Must(session.NewSession())
20-
18+
func NewLambdaClient(region string, profile string) *lambda.Lambda {
19+
sess := session.Must(session.NewSessionWithOptions(session.Options{
20+
Profile: profile,
21+
}))
2122
sess.Handlers.Build.PushBackNamed(userAgentHandler)
2223

2324
client := lambda.New(sess, &aws.Config{Region: aws.String(region)})

img2lambda/types/types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type LambdaLayer struct {
1515
type CmdOptions struct {
1616
Image string // Name of the container image
1717
Region string // AWS region
18+
Profile string // AWS credentials profile
1819
OutputDir string // Output directory for the Lambda layers
1920
DryRun bool // Dry-run (will not register with Lambda)
2021
LayerNamespace string // Prefix for published Lambda layers
@@ -36,7 +37,7 @@ type PublishOptions struct {
3637
func ConvertToPublishOptions(opts *CmdOptions) *PublishOptions {
3738
return &PublishOptions{
3839
SourceImageName: opts.Image,
39-
LambdaClient: clients.NewLambdaClient(opts.Region),
40+
LambdaClient: clients.NewLambdaClient(opts.Region, opts.Profile),
4041
LayerPrefix: opts.LayerNamespace,
4142
ResultsDir: opts.OutputDir,
4243
Description: opts.Description,

0 commit comments

Comments
 (0)