Skip to content

Instantly share code, notes, and snippets.

View gungoren's full-sized avatar
💭
lives in the clouds

Mehmet Gungoren gungoren

💭
lives in the clouds
View GitHub Profile
@gungoren
gungoren / mirroring_nginx_to_s3_bucket.conf
Created November 2, 2019 10:53
Sending a duplicated request to aws s3 bucket with nginx configuration
env AWS_ACCESS_KEY_ID;
env AWS_SECRET_ACCESS_KEY;
env S3_BUCKET_NAME;
events{
worker_connections 1024;
}
http {
server {
private void getApkSignatureHash() {
PackageManager packageManager = context.getPackageManager();
String packageName = context.getPackageName();
//Solution 1
try {
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES);
//Deprecated packageInfo.signatures;
Signature[] signatures = packageInfo.signatures;
Signature signature = signatures[0];
module "origin_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
bucket = "myorigin-${random_pet.bucket_name.id}"
acl = "private"
versioning = {
enabled = true
}
}
resource "aws_s3_object" "index" {
bucket = module.origin_bucket.s3_bucket_id
key = "index.html"
source = "${path.module}/files/index.html"
content_type = "text/html"
etag = filemd5("${path.module}/files/index.html")
}
resource "aws_s3_object" "global" {
resource "aws_lambda_function" "lambda" {
provider = aws.aws_us_east_1
function_name = "country-based-url-rewriter"
role = aws_iam_role.lambda.arn
publish = true
runtime = "nodejs16.x"
handler = "index.handler"
memory_size = 128
data "aws_iam_policy_document" "assume_role_policy" {
version = "2012-10-17"
statement {
actions = ["sts:AssumeRole"]
effect = "Allow"
principals {
identifiers = ["lambda.amazonaws.com", "edgelambda.amazonaws.com"]
type = "Service"
}
}
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const olduri = request.uri;
let newuri = olduri;
const country = request.headers["cloudfront-viewer-country"][0].value
const strIsPrimary = request.origin.s3.customHeaders.primary[0].value
module "cdn" {
source = "terraform-aws-modules/cloudfront/aws"
comment = "My Location Based CDN"
enabled = true
is_ipv6_enabled = true
price_class = "PriceClass_All"
retain_on_delete = false
wait_for_deployment = false
...
create_origin_access_identity = true
origin_access_identities = {
s3_bucket_one = "My Location Based CloudFront can access"
}
...
resource "aws_s3_bucket_policy" "cdn-cf-policy" {
bucket = module.origin_bucket.s3_bucket_id
policy = data.aws_iam_policy_document.my-cdn-cf-policy.json
}
data "aws_iam_policy_document" "my-cdn-cf-policy" {
statement {
sid = "1"
principals {
type = "AWS"