Skip to content

Instantly share code, notes, and snippets.

@limay
Forked from tpai/addArecord.sh
Created June 17, 2018 03:17
Show Gist options
  • Select an option

  • Save limay/53c81446ce807be210bc9e0435e77736 to your computer and use it in GitHub Desktop.

Select an option

Save limay/53c81446ce807be210bc9e0435e77736 to your computer and use it in GitHub Desktop.
AWS cheatsheet
HOST_ZONE_ID=
ACTION=
DNS_NAME=
# Add A record for s3 website hosting using custom domain
# Ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html
aws route53 change-resource-record-sets --hosted-zone-id $HOST_ZONE_ID --change-batch "{
\"Changes\": [{
\"Action\": \"$ACTION\",
\"ResourceRecordSet\": {
\"Name\": \"$DNS_NAME\",
\"Type\": \"A\",
\"AliasTarget\": {
\"HostedZoneId\": \"Z3O0J2DXBE1FTB\",
\"DNSName\": \"s3-website-ap-southeast-1.amazonaws.com\",
\"EvaluateTargetHealth\": false
}
}
}]
}"
# Create Distribution at Clourfront
S3_BUCKET=
CNAME_DOMAIN=
echo $(aws cloudfront create-distribution --distribution-config "{
\"PriceClass\": \"PriceClass_100\",
\"CallerReference\": \"my-distribution-$S3_BUCKET\",
\"Aliases\": {
\"Quantity\": 2,
\"Items\": [\"$CNAME_DOMAIN\", \"$S3_BUCKET\"]
},
\"Origins\": {
\"Quantity\": 1,
\"Items\": [{
\"Id\": \"my-origin\",
\"DomainName\": \"$S3_BUCKET.s3.amazonaws.com\",
\"S3OriginConfig\": {
\"OriginAccessIdentity\": \"\"
}
}]
},
\"DefaultCacheBehavior\": {
\"TargetOriginId\": \"my-origin\",
\"ForwardedValues\": {
\"QueryString\": true,
\"Cookies\": {
\"Forward\": \"none\"
}
},
\"TrustedSigners\": {
\"Enabled\": false,
\"Quantity\": 0
},
\"ViewerProtocolPolicy\": \"allow-all\",
\"MinTTL\": 60
},
\"Comment\": \"\",
\"Enabled\": true
}" | jq -r '.Distribution.DomainName')

Get Identity

Get current user identity.

CLI

aws sts get-caller-identity

Node.js

require('aws-sdk').STS().getCallerIdentity({}, function(err, data) { console.log(data); });

Put Metric Data

Put metric data to AWS CloudWatch

CLI

aws cloudwatch put-metric-data \
    --region "ap-southeast-1" \
    --metric-name [project-name] \
    --dimensions Instance=[instance-id]
    --namespace "Page View Count" \
    --unit Count \
    --value 1

Node.js

require('aws-sdk').CloudWatch().putMetricData({
    MetricData: [{
        MetricName: [project-name],
        Dimensions: [
            {
                Name: 'Instance',
                Value: [instance-id]
            }
        ],
        Unit: 'Count',
        Value: 1
    }],
    Namespace: 'Page View Count'
}, (err, data) => {
    if (err) {
        console.log(err, err.stack);
    } else {
        console.log(data);
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment