Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ Amazon API Gateway integration with AWS WAF

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š Amazon API Gateway integration with AWS WAF


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Amazon API Gateway integration with AWS WAF

Amazon API Gateway integration with AWS WAF

Introduction

Amazon API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. With a few clicks in the AWS Management Console, you can create an API that acts as a โ€œfront doorโ€ for applications to access data, business logic, or functionality from your back-end services, such as workloads running on Amazon Elastic Compute Cloud (Amazon EC2), code running on AWS Lambda, or any web application.

Amazon API Gateway supports several types of integrations with AWS services and third-party services. In this post, we will focus on the integration with AWS WAF. AWS WAF is a web application firewall that helps protect your web applications from common web exploits that could affect application availability, compromise security, or consume excessive resources. AWS WAF gives you control over which traffic to allow or block to your web applications by defining customizable web security rules. You can use AWS WAF to create security rules that block common attack patterns, such as SQL injection or cross-site scripting, and rules that filter specific traffic patterns, such as requests from specific IP addresses or referring websites.

Why use Amazon API Gateway integration with AWS WAF?

Amazon API Gateway integration with AWS WAF is a great way to protect your APIs from common web exploits that could affect application availability, compromise security, or consume excessive resources. AWS WAF gives you control over which traffic to allow or block to your APIs by defining customizable web security rules. You can use AWS WAF to create security rules that block common attack patterns, such as SQL injection or cross-site scripting, and rules that filter specific traffic patterns, such as requests from specific IP addresses or referring websites.

Demo - Amazon API Gateway integration with AWS WAF by using AWS CDK

In this demo, we will create an API Gateway API with a single GET method that will return a JSON response. We will then create a WAF rule that will block requests from a specific IP address. We will then test the API and see that the request is blocked. We will then remove the WAF rule and test the API again to see that the request is allowed.

Create an API Gateway API

First, we will create an API Gateway API with a single GET method that will return a JSON response. We will use the AWS CDK to create the API Gateway API.

// lambda function
const testFn = new NodejsFunction(this, 'MyFunction', {
  entry: './function/index.ts',
  runtime: lambda.Runtime.NODEJS_18_X,
  handler: 'main',
  bundling: {
    externalModules: ['aws-sdk'],
    minify: true,
  },
})

// api gateway, this is just for testing
const api = new apigateway.LambdaRestApi(this, 'test-api', {
  handler: testFn,
  deployOptions: {
    stageName: 'test',
  },
})

Create a WAF ACL and WAF Rule

Next, we will create a WAF ACL and a WAF Rule allowing only requests from a specific location. We will use the AWS CDK to create the WAF ACL and WAF Rule.

const webACL = new wafv2.CfnWebACL(this, 'webACL', {
  name: 'webACL',
  description: 'This is WebACL for Auth APi Gateway',
  scope: 'REGIONAL', // or CLOUDFRONT for CloudFront
  defaultAction: { block: {} }, // default action is block all request
  visibilityConfig: {
    cloudWatchMetricsEnabled: true,
    metricName: 'webACL', // metric name for CloudWatch
    sampledRequestsEnabled: true,
  },

  rules: [
    {
      name: `demo-api-auth-gateway-geolocation-rule`,
      priority: 30,
      action: { allow: {} },
      visibilityConfig: {
        metricName: `demo-AuthAPIGeoLocation`,
        cloudWatchMetricsEnabled: true,
        sampledRequestsEnabled: false,
      },
      statement: {
        geoMatchStatement: {
          countryCodes: ['US', 'VN'], // allow US and VN IP. You can add more country codes
        },
      },
    },
  ],
})

This will create a WAF ACL with a single WAF Rule allowing only requests from a specific location(US and VN). We will then associate the WAF ACL with the API Gateway API.

// Web ACL Association
const webACLAssociation = new wafv2.CfnWebACLAssociation(this, 'webACLAssociation', {
  webAclArn: webACL.attrArn, // Web ACL ARN from above
  // For an Amazon API Gateway REST API: arn:aws:apigateway:region::/restapis/api-id/stages/stage-name
  resourceArn: Fn.join('', [
    'arn:aws:apigateway:', // service
    Stack.of(this).region, // region
    '::/restapis/', // resource type
    api.restApiId, // api id
    '/stages/', // resource type
    api.deploymentStage.stageName, // stage name
  ]),
})

// make sure api gateway is deployed before web ACL association
webACLAssociation.node.addDependency(api)

This will associate the WAF ACL with the API Gateway API. We will then test the API and see that the request is blocked. We will then remove the WAF rule and test the API again to see that the request is allowed.

The code for this demo is available on GitHub. You can deploy the demo by running the following commands.

git clone
cd apig-waf-cdk
yarn install
yarn deploy

Testing the API

After deploying the demo, we will test the API. We will use the following command to test the API.

curl -X GET https://<api-id>.execute-api.<region>.amazonaws.com/test

The response should be similar to the following.

{
  "message": "Hello from Lambda!"
}

Now, we will remove 'VN'(or your country code) from the WAF Rule and test the API again. We will use the following command to test the API.

curl -X GET https://<api-id>.execute-api.<region>.amazonaws.com/test

The response should be similar to the following.

{
  "message": "Forbidden"
}

The request is blocked because the request is from a location that is not allowed by the WAF Rule.

Conclusion

In this post, we have seen how to use Amazon API Gateway integration with AWS WAF by using AWS CDK. We have also seen how to test the API to see that the request is blocked.

The source code for this demo is available on GitHub.

That's all for now. Thanks for reading. If you have any questions or comments, please leave them below. I will try to answer them as soon as possible.

References

...



๐Ÿ“Œ Amazon API Gateway integration with AWS WAF


๐Ÿ“ˆ 49.98 Punkte

๐Ÿ“Œ Aws-Waf-Header-Analyzer - The Purpose Of The Project Is To Create Rate Limit In AWS WaF Based On HTTP Headers


๐Ÿ“ˆ 44.92 Punkte

๐Ÿ“Œ AWS WAF vs. open-appsec ML-Based open source WAF


๐Ÿ“ˆ 37.4 Punkte

๐Ÿ“Œ Choosing the Right API Gateway: Pricing Models for Amazon API Gateway, Apigee, Kong, and Apache APISIX


๐Ÿ“ˆ 34.08 Punkte

๐Ÿ“Œ Securing and Monitoring Your Data Pipeline: Best Practices for Kafka, AWS RDS, Lambda, and API Gateway Integration


๐Ÿ“ˆ 31.86 Punkte

๐Ÿ“Œ API Gateway REST API with Lambda Integration


๐Ÿ“ˆ 30.55 Punkte

๐Ÿ“Œ Deploy Your First Web App on AWS with AWS Amplify, Lambda, DynamoDB and API Gateway


๐Ÿ“ˆ 30.5 Punkte

๐Ÿ“Œ WAF, cIAM und API-Gateway mรผssen Hand in Hand gehen


๐Ÿ“ˆ 30.38 Punkte

๐Ÿ“Œ nOps brings API integration with AWS Well-Architected Tool to support AWS Well-Architected Reviews


๐Ÿ“ˆ 30.15 Punkte

๐Ÿ“Œ Securing Your Web Application with AWS WAF and AWS Shield


๐Ÿ“ˆ 29.99 Punkte

๐Ÿ“Œ WAF Buster - Disrupt WAF By Abusing SSL/TLS Ciphers


๐Ÿ“ˆ 29.87 Punkte

๐Ÿ“Œ Why Replace Traditional Web Application Firewall (WAF) With New Age WAF?


๐Ÿ“ˆ 29.87 Punkte

๐Ÿ“Œ Gotestwaf - Go Test WAF Is A Tool To Test Your WAF Detection Capabilities Against Different Types Of Attacks And By-Pass Techniques


๐Ÿ“ˆ 29.87 Punkte

๐Ÿ“Œ Waf-Bypass - Check Your WAF Before An Attacker Does


๐Ÿ“ˆ 29.87 Punkte

๐Ÿ“Œ What is a Web Application Firewall (WAF)? Different Types of WAF


๐Ÿ“ˆ 29.87 Punkte

๐Ÿ“Œ DevOps didnโ€™t kill WAF, because WAF will never truly die


๐Ÿ“ˆ 29.87 Punkte

๐Ÿ“Œ Cook a recipe with AWS: A simple API using API-Gateway


๐Ÿ“ˆ 29.19 Punkte

๐Ÿ“Œ How to Deploy a Serverless Node.js API with AWS API Gateway?


๐Ÿ“ˆ 29.19 Punkte

๐Ÿ“Œ AWS: Integrating OpenAPI With the Amazon API Gateway and Lambda Functions


๐Ÿ“ˆ 26.16 Punkte

๐Ÿ“Œ Validating Request Parameters and Body in Amazon API Gateway with AWS CDK


๐Ÿ“ˆ 26.16 Punkte

๐Ÿ“Œ Learning AWS day by Day - Day 58 - Amazon API Gateway


๐Ÿ“ˆ 26.16 Punkte

๐Ÿ“Œ TIBCO FTP Community Edition up to 6.5.0 on Windows Server/C API/Golang API/Java API/.Net API access control


๐Ÿ“ˆ 24.86 Punkte

๐Ÿ“Œ Meet AI Gateway: An Open-Sourced Fast AI Gateway Routed to 100+ Large Language Models LLMs with One Fast and Friendly API


๐Ÿ“ˆ 24.68 Punkte

๐Ÿ“Œ Async Integration with Step Functions from API Gateway via CDK


๐Ÿ“ˆ 24.33 Punkte

๐Ÿ“Œ Fortify Your Elastic Load Balancer: Best Practices for Secure API Gateway Integration


๐Ÿ“ˆ 24.33 Punkte

๐Ÿ“Œ AWS Networking - AWS VPC, Subnets, Security Groups, NAT Gateway & IP Addresses


๐Ÿ“ˆ 24.28 Punkte

๐Ÿ“Œ AWS: Overview of AWS Direct Connect, Connect Location, Connect Endpoint and Connect Gateway


๐Ÿ“ˆ 24.28 Punkte

๐Ÿ“Œ Difference between AWS VPC Peering and AWS Transitย Gateway


๐Ÿ“ˆ 24.28 Punkte

๐Ÿ“Œ WAF integration: Acunetix and F5 BigIP ASM


๐Ÿ“ˆ 23.82 Punkte

๐Ÿ“Œ WAF integration: Acunetix and FortiWeb


๐Ÿ“ˆ 23.82 Punkte

๐Ÿ“Œ Appdome upgrades MOBILEBot Defense for tailored WAF integration


๐Ÿ“ˆ 23.82 Punkte

๐Ÿ“Œ Data API for Amazon Aurora Serverless v2 with AWS SDK for Java - Part 6 Comparing cold and warm starts between Data API and JDBC


๐Ÿ“ˆ 23.14 Punkte

๐Ÿ“Œ Extension for Burp Suite which uses AWS API Gateway to change your IP on every request.


๐Ÿ“ˆ 22.97 Punkte











matomo