Skip to content

Instantly share code, notes, and snippets.

@henhal
Created April 20, 2017 06:01
Show Gist options
  • Save henhal/782dac50ba53ae164af0e95a41108af5 to your computer and use it in GitHub Desktop.
Save henhal/782dac50ba53ae164af0e95a41108af5 to your computer and use it in GitHub Desktop.
Transferring SSH keys to Elastic Beanstalk in order to access private gits (for npm etc)
Resources:
AWSEBAutoScalingGroup:
Metadata:
? "AWS::CloudFormation::Authentication"
:
S3Auth:
buckets:
- <my-bucket>
roleName:
? "Fn::GetOptionSetting"
:
DefaultValue: aws-elasticbeanstalk-ec2-role
Namespace: "aws:asg:launchconfiguration"
OptionName: IamInstanceProfile
type: s3
files:
/root/.ssh/github-eb-key:
authentication: S3Auth
mode: "000600"
owner: root
group: root
source: "https://s3-eu-west-1.amazonaws.com/<my-bucket>/github-eb-key"
/root/.ssh/config:
mode: "000600"
owner: root
group: root
content: |
Host github.com
IdentityFile /root/.ssh/github-eb-key
IdentitiesOnly yes
UserKnownHostsFile=/dev/null
StrictHostKeyChecking no
@henhal
Copy link
Author

henhal commented Apr 20, 2017

With this in .ebextensions, your EB will fetch a SSH private key from S3 at /github-eb-key. Very useful if your EB needs to source repositories from git, or other places requiring authentication through SSH keys, for example if using NPM with private repositories sourced through github.

@tobsn
Copy link

tobsn commented Oct 2, 2019

@henhal is this still working with container_command? it looks here like its not finding the key

@henhal
Copy link
Author

henhal commented Oct 2, 2019

@tobsn I'm sorry but it's been a year and a half since I last used Elastic Beanstalk so I don't know if it's still valid. I do know that I used this in combination with other config files making use of container_commands though, so I have no reason to believe it wouldn't still work.

@tobsn
Copy link

tobsn commented Oct 3, 2019

@henhal yeah it somehow started working... must have been the mode settings, idk... :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment