chaitanya Thota
chaitanya Thota

Reputation: 1

I created CFT file APG-lambda. CFT-GIT-Jenkins my work flow

I'm posting my code. I created CFT file APG-lambda. CFT-GIT-Jenkins. My jenkin job is successful & sack-created complete. In apigateway while I'm doing test getting internalserver500. For restapi I need use headers in zipfile? Note: code has some syntax error because the problem is copy and paste. THANKS

Parameters:

IAMRole:

    Description: IAM role of the account and region
    Type: String

AppID:

    Description: APPID of the application
    Type: String

UserID:

    Description: Userid of the application
    Type: String

Role:

    Description: Role of the Lambda usage app db or web
    Type: String

LambdaFunctionName:

    Description: Name of the existing function
    Type: String
    Default: LambdaApiPOCTrigger-01

VpcEndpointId:

    Description: Name of the VPCEndpoint ID
    Type: String
    Default: vpce-06af867930d6c6b56

Resources:

lambdaEventPocSchedule:

    Type: AWS::Lambda::Function
    Properties:
      Description: "Lambda function to trigger lambda after every 1 hours."
      Handler: 'index.lambda_handler'
      Runtime: python3.8
      FunctionName: 'lambdaApiPOCTrigger-01'
      Role: !Ref IAMRole
      Tags:
        - Key: Name
          Value: lambdaApiPOCTrigger-01
        - Key: Userid
          Value: 
            Ref: UserID
        - Key: Vsad
          Value: 
            Ref: AppID
        - Key: Role
          Value: 
            Ref: Role
      VpcConfig:
        SecurityGroupIds:
          - sg-0641cf79
          - sg-e5f49f9d
          - sg-b7f69d9e
          - sg-b7f69d9e
          - sg-95f299eb
          - sg-6645cb19
        SubnetIds:
          - subnet-aa282cf1
      MemorySize: 512
      Timeout: '300'
      Code:
        ZipFile: |
          def lambda_handler(event, context):
              print("Hello")
              return {"statuscode": 200, "body": "Lambda executed successfully"}

PocApiGateway:

    Type: AWS::ApiGateway::RestApi
    Properties:
      Name: PocLambdaAPI
      EndpointConfiguration:
        Types:
          - PRIVATE
      Policy:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Action: execute-api:Invoke
            Resource: execute-api://*
            Principal: "*"
            Condition:
              StringEquals:
                aws:SourceVpce: !Ref VpcEndpointId

PocApiResource:

    Type: AWS::ApiGateway::Resource
    Properties:
      ParentId: !GetAtt PocApiGateway.RootResourceId
      PathPart: test
      RestApiId: !Ref PocApiGateway

PocApiMethod:

    Type: AWS::ApiGateway::Method
    DependsOn:
      - lambdaEventPocSchedule

Properties:

      HttpMethod: GET
      ResourceId: !Ref PocApiResource
      RestApiId: !Ref PocApiGateway
      AuthorizationType: AWS_IAM
      ApiKeyRequired: true
      Integration:
        IntegrationHttpMethod: POST
        Type: AWS_PROXY
        Uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:084309170734:function:lambdaApiPOCTrigger-01/invocations"
      MethodResponses:
        - StatusCode: "200"
    LambdaApiGatewayPermission:
    Type: AWS::Lambda::Permission
    Properties:
      Action: Lambda:InvokeFunction
      FunctionName: !Ref lambdaEventPocSchedule
      Principal: apigateway.amazonaws.com
      SourceArn: !Sub arn:aws:execute-api:us-east-1:084309170734:PocLambdaAPI/*

PocApiDeployment:

Type: AWS::ApiGateway::Deployment

DependsOn:

    - PocApiMethod

Properties:

    RestApiId: !Ref PocApiGateway
    StageName: test

Expecting apigateway call invokes to lambdafunction

Upvotes: -1

Views: 14

Answers (0)

Related Questions