This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env AWS_ACCESS_KEY_ID; | |
env AWS_SECRET_ACCESS_KEY; | |
env S3_BUCKET_NAME; | |
events{ | |
worker_connections 1024; | |
} | |
http { | |
server { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module "origin_bucket" { | |
source = "terraform-aws-modules/s3-bucket/aws" | |
bucket = "myorigin-${random_pet.bucket_name.id}" | |
acl = "private" | |
versioning = { | |
enabled = true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
create_origin_access_identity = true | |
origin_access_identities = { | |
s3_bucket_one = "My Location Based CloudFront can access" | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
OlderNewer