By using AWS re:Post, you agree to the AWS re:Post Terms of Use

What is the function of this API endpoint: "https://okakvoavfg.execute-api.eu-west-1.amazonaws.com/" in Cost Intelligence Dasboard setup?

0

I'm setting up a Cost Intelligence Dashboard, and as part, I was deploying the cur-aggregation stack in the management account. I noticed that the API_ENDPOINT "https://okakvoavfg.execute-api.eu-west-1.amazonaws.com/" is being used. Does anyone know why this endpoint is used and what its purpose is?

  CIDLambdaAnalytics:
    Type: AWS::Lambda::Function
    Properties:
      Runtime: python3.11 # before updating 
      FunctionName:
        Fn::Sub: ${ResourcePrefix}-CID-Analytics
      Handler: index.lambda_handler
      MemorySize: 128
      Role:
        Fn::GetAtt: CIDLambdaAnalyticsRole.Arn
      Timeout: 15
      Environment:
        Variables:
          **API_ENDPOINT: https://okakvoavfg.execute-api.eu-west-1.amazonaws.com/**
      Code:
        ZipFile: |
          import json
          import boto3
          import os
          import cfnresponse
          import urllib3
          import uuid

          http = urllib3.PoolManager()
          **endpoint=os.environ["API_ENDPOINT"]**
          account_id=boto3.client("sts").get_caller_identity()["Account"]

          def execute_request(action,dashboard_id,via_key):
              try:
                  message=None
                  payload={'dashboard_id': dashboard_id, 'account_id': account_id, via_key: 'CFN'}
                  encoded_data = json.dumps(payload).encode('utf-8')
                  r = http.request(action,endpoint,body=encoded_data,headers={'Content-Type': 'application/json'})
                  if r.status!=200:
                      message=f"This will not fail the deployment. There has been an issue logging action {action}  for dashboard {dashboard_id} and account {account_id}, server did not respond with a 200 response,actual  status: {r.status}, response data {r.data.decode('utf-8')}. This issue will be ignored"
              except urllib3.exceptions.HTTPError as e:
                message=f"Issue logging action {action}  for dashboard {dashboard_id} and account {account_id}, due to a urllib3 exception {str(e)} . This issue will be ignored"
              return message


          def register_deployment(action,dashboards):
              message=f"Successfully logged  {action} for {dashboards}"
              for dashboard_id in dashboards:
                  if action == 'CREATE':
                      message=execute_request('PUT',dashboard_id,'created_via')
                  elif action == 'UPDATE':
                      message=execute_request('PATCH',dashboard_id,'updated_via')
                  elif action == 'DELETE':
                      message=execute_request('DELETE',dashboard_id,'deleted_via')
                  if message is None:
                      message=f"Successfully logged  {action} for {dashboards} "
              #Do not stop deployment if we're not able to successfully record this deployment, still return true
              return ("True",message)


          def lambda_handler(event, context):
              if event['RequestType'] == 'Create':
                  res, reason = register_deployment('CREATE',event['ResourceProperties']['DeploymentType'])
              elif event['RequestType'] == 'Update':
                  res, reason = register_deployment('UPDATE',event['ResourceProperties']['DeploymentType'])
              elif event['RequestType'] == 'Delete':
                  res, reason = register_deployment('DELETE',event['ResourceProperties']['DeploymentType'])
              else:
                  res = False
                  reason = "Unknown operation: " + event['RequestType']

              response_data = {'Reason': reason}
              print(response_data)
              if 'PhysicalResourceId' in event.keys() and event['PhysicalResourceId'] is not None:
                  physicalResourceId=event['PhysicalResourceId']
              else:
                  physicalResourceId=str(uuid.uuid1())
              if res:
                  cfnresponse.send(event, context, cfnresponse.SUCCESS, response_data, physicalResourceId )
              else:
                  cfnresponse.send(event, context, cfnresponse.FAILED, response_data, physicalResourceId )
    Metadata:
      cfn_nag:
        rules_to_suppress:
          - id: 'W89'
            reason: "This Lambda does not require VPC"
          - id: 'W92'
            reason: "One Time execution. No need for ReservedConcurrentExecutions"
1 Answer
2

This API endpoint tracks adoption of the solution by the team that manages it. The Lambda runs when you create, update or delete the stack and collects the account number. If you want to opt out, you can remove this or replace the API endpoint with an empty string.

AWS
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions