How to AWS get API key value in serverless

How to get the API key value in output using physical or logical ID?. because I want to export and import it in another serverless.yml file, can you help me with it?

You could add stack output to your serverless.yml. A couple ways to do things. If you wanted to save in an ssm parameter, you could reference it in some other build.

If you simply want to refer to what wil be the ApiId in another yml file, you can include the file in your serverless.yml: ${file(serverless.functions.yml)} Then you can simply use a “Ref: ApiGatewayRestApi” in the included file to refer to the logical name the generated stack uses for your api.

Finally, if you want to save it for later reference, you can store the value in SSM - then refer to it in another serverless build using ${ssm:/path-to-your-value}

resources:
  Resources:
    RestApi:
      Type: AWS::SSM::Parameter
      Properties:
        Name: /services/${self:service}-${opt:stage}/apiId
        Type: String
        Value:
          Ref: ApiGatewayRestApi

  Outputs:
    RestApi:
      Value: 
        Ref: ApiGatewayRestApi
1 Like