Package: cdk-cloudfront-geo-locator
CloudfrontGeoLocatorTheCloudfrontGeoLocatoris an AWS CDK construct that automates the setup of a CloudFront distribution with an Origin Request Lambda function, enabling applications to determine the geolocation of their users based on incoming HTTP requests. It's an ideal solution for developers looking to enhance their cloud applications with geolocation awareness without delving into the complexities of AWS configurations.Table of ContentsInstallationUsageDocumentationGeolocation Endpoint ResponseContributingPull Request GuidelinesLicenseInstallationTo installCloudfrontGeoLocatorconstruct library using npm, run the following command:npmicdk-cloudfront-geo-locatorUsageTo initialize theCloudfrontGeoLocatorconstruct you can use the following code:importcdk=require('aws-cdk-lib');import{Construct}from'constructs';import{CloudfrontGeoLocator}from'cdk-cloudfront-geo-locator';//stackinitializationwithdefaultpropsconstgeoLocator=newCloudfrontGeoLocator(this,'GeoLocator');//stackinitializationwithcustompropsconstgeoLocatorWithProps=newCloudfrontGeoLocator(this,'GeoLocatorWithProps',{s3BucketName:'cloudfront-origin-bucket-name',//optionallambdaFunctionName:'cloudfront-origin-request-edge-lambda-function-name',//optionalcloudfrontCachePolicyName:'cloudfront-cache-policy-name',//optionalcloudfrontOriginRequestPolicyName:'cloudfront-origin-request-policy-name',//optionalcloudfrontPriceClass:cloudfront.PriceClass.PRICE_CLASS_100,//optional});//stackinitializationwithcustomdomainconstcustomDomainGeoLocator=newCloudfrontGeoLocator(this,'CustomDomainGeoLocator',{customDomainName:'example.com',customDomainCertificateArn:'arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012',});//exportedpropertiesconsole.log(geoLocator.s3BucketArn);//TheARNoftheS3bucket.console.log(geoLocator.lambdaFunctionArn);//TheARNoftheLambdafunction.console.log(geoLocator.lambdaFunctionVersion);//ThecurrentversionoftheLambdafunction.console.log(geoLocator.distributionId);//TheIDoftheCloudFrontdistribution.console.log(geoLocator.distributionDomainName);//ThedomainnameoftheCloudFrontdistribution.console.log(geoLocator.cloudfrontCachePolicyId);//TheIDoftheCloudFrontcachepolicy.console.log(geoLocator.cloudfrontOriginRequestPolicyId);//TheIDoftheCloudFrontoriginrequestpolicy.DocumentationTo initialize theCloudfrontGeoLocatorconstruct you can use the following props:/***PropertiesfortheCloudfrontGeoLocatorconstruct.*/exportinterfaceCloudfrontGeoLocatorPropsextendsResourceProps{/***Auniquenametoidentifythes3bucket.**@default-cloudfront-geo-locator-origin*/readonlys3BucketName?:string;/***Auniquenametoidentifythelambdafunction.**@default-cloudfront-geo-locator*/readonlylambdaFunctionName?:string;/***Auniquenametoidentifythecloudfrontcachepolicy.**@default-CloudfrontGeoLocatorCachePolicy*/readonlycloudfrontCachePolicyName?:string;/***Auniquenametoidentifythecloudfrontoriginrequestpolicy.**@default-CloudfrontGeoLocatorOriginRequestPolicy*/readonlycloudfrontOriginRequestPolicyName?:string;/***ThepriceclassfortheCloudFrontdistribution.**@default-PRICE_CLASS_100*/readonlycloudfrontPriceClass?:cloudfront.PriceClass;/***ThedomainnamefortheCloudFrontdistribution.**@default-undefined*/readonlycustomDomainName?:string;/***TheARNofthecertificate.**@default-undefined*/readonlycustomDomainCertificateArn?:string;}Geolocation Endpoint ResponseThe geolocation endpoint returns a JSON object with the following properties:{"country":"TR","countryName":"Türkiye","countryRegion":"35","countryRegionName":"Izmir","city":"Izmir"}ContributingWe welcome contributions! Please reviewcode of conductandcontributing guideso that you can understand what actions will and will not be tolerated.Pull Request GuidelinesThemainbranch is just a snapshot of the latest stable release. All development should be done in development branches.Do not submit PRs against themainbranch.Work in thesrcfolder andDO NOTcheckindistin the commits.It's OK to have multiple small commits as you work on the PRIf adding a new feature add accompanying test case.If fixing bug,Add accompanying test case if applicable.Provide a detailed description of the bug in the PR.If you are resolving an opened issue add issue number in your PR title.LicenseCloudfrontGeoLocatorisMIT licensed.