Skip to main content

Template for API gateway creation using CI-CD

Below is the template which can be used for api gateway creation in AWS.

Template :


AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  Application containing RestAPI for First

Globals:
  Function:
    Timeout: 30

Parameters:
  #s3 bucket name
  BucketName:
    Type: String
    Description: Bucket to be used
    Default: lambda-deployment-d1

  EnvironmentName:
    Type: 'AWS::SSM::Parameter::Value<String>'
    Default: /<parameterPath>/EnvironmentName                        
    # /myDemo/d1/EnvironmentName

  StageName:
    Type: 'AWS::SSM::Parameter::Value<String>'
    Default: /<parameterPath>/StageName                             
    # /myDemo/d1/EnvironmentName

  BucketPrefix:
    Type: String
    Description: bucket prefix
    Default: first-project-api                                   
    # /myDemo/d1/EnvironmentName

  CertificateARN:
    Type: 'AWS::SSM::Parameter::Value<String>'
    Default: /<parameterPath>/CertificateARN    
    # /myDemo/d1/CertificateARN

  DomainName:
    Type: 'AWS::SSM::Parameter::Value<String>'
    Default: /<parameterPath>/DomainName        
    # /myDemo/d1/DomainName



Resources:

  LambdaRoleForVPCResources:
    Type: AWS::IAM::Role                                            
    # https://serverless.com/framework/docs/providers/aws/guide/resources/
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
        - Effect: "Allow"
          Principal:
            Service:
            - "lambda.amazonaws.com"
          Action:
          - "sts:AssumeRole"
      Policies:
      #policy name
      - PolicyName: "LambdaVpcPolicy"
        PolicyDocument:
          Version: "2012-10-17"
          Statement:
          - Effect: "Allow"
            Action:
            - "logs:CreateLogGroup"
            - "logs:CreateLogStream"
            - "logs:PutLogEvents"
            - "ec2:CreateNetworkInterface"
            - "ec2:DescribeNetworkInterfaces"
            - "ec2:DeleteNetworkInterface"
            - "dynamodb:*"
            - "apigateway:*"
            Resource: "*"

  # creates api gateway using swagger.yml

FirstRestAPI: Type: AWS::Serverless::Api # https://docs.aws.amazon.com/serverless-alication-model/latest/developerguide/serverless-sam-template.html Properties: Name: !Join ['', [' first-rest-api-', !Ref EnvironmentName]] StageName: !Ref StageName # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-transform.html DefinitionBody: 'Fn::Transform': # Fn::Transform specifies a macro to perform custom processing on part of a stack template. Name: 'AWS::Include' # Replace <bucket> with your bucket name Parameters: Location: !Join ['', [ 's3://',!Ref BucketName, '/',!Ref BucketPrefix, '/swagger.yaml' ] ] FirstRestAPIGetByItem: Type: AWS::Serverless::Function # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-transform.html FunctionName: !Join ['', [ 'FirstRestAPIGetByItem-', !Ref EnvironmentName ] ] Properties: #python code base containg lambdas which process request CodeUri: First-rest-api/build/ #lambda name and its method Handler: ItemByName.lambda_handler Runtime: python3.7 #role of lambda Role: !GetAtt LambdaRoleForVPCResources.Arn #these are environment variable which are required for lambda Environment: Variables: First_TABLE: !Join ['', [ 'Item-table-', !Ref EnvironmentName ] ] Events: #listner of lambda fucntion ...this can be api kinesis or any aws service SubscribeToEvents: #type of service to subscribe Type: Api Properties: #name of service this is declared above RestApiId: !Ref FirstRestAPI #path to access api this is also maed to swagger.yml Path: /item #method type Method: post #done for static name creation --create name of api ApiDomainName: Type: 'AWS::ApiGateway::DomainName' Properties: CertificateArn: !Ref CertificateARN DomainName: !Join ['', ['first-api-', !Ref EnvironmentName, '.', !Ref DomainName]] #done for static name creation -- create mapping for api APIMaing: Type: 'AWS::ApiGateway::BasePathMapping' Properties: BasePath: v1 DomainName: !Ref ApiDomainName RestApiId: !Ref FirstRestAPI Stage: !Ref StageName #generates output url for the generated services Outputs: ItemByNameApiUrl: Description: URL of API endpoint Value: !Join - '' - - https:// - !Ref FirstRestAPI - '.execute-api.' - !Ref 'AWS::Region' - '.amazonaws.com/' - !Ref StageName - '/item' #shows details of all created api's FirstRestAPIGetByItem: Description: " Rest API Function ARN" Value: !GetAtt FirstRestAPIGetByItem.Arn

Comments

Popular posts from this blog

Extent report plugin for cucumber framework

Extent Reports  are the most popular  reporting  used with Selenium. ExtentReport API makes our life easy to generate interactive  report  with simple configuartions. It supports almost all Java and .NET test frameworks such as TestNG , JUnit , NUnit etc Here we are discussing about  a plugin which is build on  Extent Report specially for Cucumber. This plugin is used to simple out the implementation of  Extent Report  in  Cucumber Framework .  We are creating a maven project to implement the integration of our plugin with cucumber 1. Create new maven project in any tool eclipse/sts/intellij 2. Open pom.xml and update below entries. Step 1 : Add Cucumber Extent Reporter library to Maven Project Add  cucumber-extentsreport <dependency>      <groupId> com.vimalselvam </groupId>      <artifactId> cucumber-extentsreport </artif...

java: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.

  In order to make projects compile with the existing builds of Lombok processor, as a workaround you can use the flag -Djps.track.ap.dependencies=false which should be added to File | Settings | Build, Execution, Deployment | Compiler | Build process VM options field. This will disable collection of dependencies specified by an annotation processor when Filer methods are called

Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Unable to find main class

Solutions:  Solution 1 : You needed to change the packaging parameter to jar from pom. Also, the repositories , pluginRepositories , the maven-compiler-plugin and the spring-boot-maven-plugin's version and executions weren't needed. Solution 2:  Try mvn install and see if it works Solution 3: Preview: <properties> <!-- The main class to start by executing java -jar --> <start-class> com.mycorp.starter.HelloWorldApplication </start-class> </properties> Solution 4: Enable the main() method in your Application.java. Configure spring-boot-maven-plugin to specify the class with the main class (Spring should find it anyway if you have one, but good to be explicit): Preview: <plugin> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-maven-plugin </artifactId> <version> ${spring-boot-version} </version>...