Skip to content

Instantly share code, notes, and snippets.

View neilkuan's full-sized avatar
🎯
Focusing

Neil Kuan neilkuan

🎯
Focusing
View GitHub Profile
@neilkuan
neilkuan / cdk_stack.py
Created April 4, 2020 08:13
cdk_stack.py
##from aws_cdk import core
#import modlue you needed
import os.path as path
import sys
from aws_cdk import (
core,
aws_ec2 as ec2,
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "CrossAccountPull",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::1333333333:root"
},
# need awscli >= 1.16.x , docker
# aws ecr get-login --registry-ids < ecr-account-id > --region < region-you-want > --no-include-email
#way 1.
# Get docker registry token from A account ECR
[ec2-user@192-168-0-99 ~ ] aws ecr get-login --registry-ids 1333333333 --region ap-northeast-1 --no-include-email
#--output
docker login -u AWS -p eyJwYXlsb2FkIjoi....NUZCeTkydVU2b2R9 https://1333333333.dkr.ecr.us-east-1.amazonaws.com
# Copy output for Login A account ECR
$ curl -LO https://eksworkshop.com/beginner/110_irsa/deploy.files/iam-pod.yaml
--- inside
apiVersion: apps/v1
kind: Deployment
metadata:
name: eks-iam-test
spec:
replicas: 1
selector:
matchLabels:
exports.handler = (event, context, callback) => {
// Extract the request from the CloudFront event that is sent to Lambda@Edge
var request = event.Records[0].cf.request;
var newuri = ''
// Extract the URI from the request
var olduri = request.uri;
if (olduri == '/'){
newuri = olduri+ 'index.html';
}else{
version: "3.7"
services:
nexus:
image: "sonatype/nexus3:3.19.1"
container_name: "nexus"
restart: always
ports:
- "8081:8081"
- "5000:5000"
volumes:
#!/bin/bash
TMPFILE=/tmp/u53tempfile
TMPFILE_URI="file://$TMPFILE"
AWS=/usr/local/bin/aws
function try {
eval $*
if [ $? -ne 0 ]; then
echo "Error while evaluating \"$*\", exiting..."
@neilkuan
neilkuan / init-super-user.sh
Created September 29, 2020 02:28
Use AWS CLI to create Super User , so fast !!!
#!/bin/bash
set pipefail
if [ $# != 2 ]
then
echo "Please give username and password \n ./init-super-user.sh tempuser 2wsx#EDCv ..."
exit 1
fi
USER_NAME=$1
@neilkuan
neilkuan / send-publickey-connect.sh
Last active May 9, 2022 09:55
send public key to connect ec2
#!/bin/bash
instanceId=$1
pubkey="$HOME/.ssh/id_rsa.pub"
sshUser='ec2-user'
az=$(aws ec2 describe-instances --instance-id ${instanceId} --query 'Reservations[0].Instances[0].Placement.AvailabilityZone' --output text)
echo "sending public key to ${instanceId}"
aws ec2-instance-connect send-ssh-public-key --instance-id ${instanceId} --instance-os-user ${sshUser} \
@neilkuan
neilkuan / example-register-docker-runner.sh
Last active November 24, 2020 02:34
Example Register Docker Runner Shell Script .
#!/bin/bash
RUNNER_TOKEN=$1
# Register
docker run -it --rm -v /root/gitlab-runner-sit:/etc/gitlab-runner gitlab/gitlab-runner:alpine \
register --non-interactive --url https://gitlab.com \
--registration-token ${RUNNER_TOKEN} --docker-pull-policy if-not-present \
--docker-volumes /var/run/docker.sock:/var/run/docker.sock --executor docker \
--docker-volumes /root/.m2:/root/.m2 \
--docker-image alpine:latest --description "Docker Runner" --docker-privileged \