Create GitHub action with extra resource for Javascript - javascript

I have built a GitHub Action with the Javascript "method".
I have the following action.yaml file:
name: 'xxx Action'
author: 'xxx'
description: 'Runs `xxx` in your repository.'
branding:
icon: 'code'
color: 'purple'
inputs:
token:
description: 'Txxxxunt'
required: true
groupId:
description: 'xxxx'
required: true
runs:
using: 'node16'
main: './build/index.js'
This is how my build folder looks like:
My index.js must use the keytar.node file. Is there a way to include this extra file in the action as well?
I know that GitHub will run the build/index.js file but it will fail because it will miss the extra file.
Is there a way to include this file Only With Javascript method? I do know I could do the same with Docker method

Related

AWS::Appsync:Resolver Cloudformation error using Javascript Resolver in Code block in YML using Serverless Framework

I am having an issue while creating AWS::Appsync:Resolver Cloudformation in Serverless Framework using Javascript resolver.
My Javascript Resolver code in root dir /src/resolvers/jsResolver.js which I have attached to AWS::AppSync::Resolver cloudformation in code block. I have also installed npm plugin for appsync utils in my package.json
import { util } from '#aws-appsync/utils';
export function request(ctx) {
const {source, args} = ctx
return {
operation: 'Invoke',
payload: { field: ctx, arguments: args, source },
};
}
export function response(ctx) {
util.error("Failed to fetch relatedPosts", "LambdaFailure", ctx.prev.result)
return ctx.result;
}
My AWS::AppSync::Resolver Cloudformation is below in YML file also I have used Code as its Mandatory if I have declared it as APPSYNC_JS Runtime
AppSyncJsResolver:
Type: AWS::AppSync::Resolver
Properties:
ApiId: !GettAtt Graphql.APiId
Kind: PIPELINE
Code: ./src/resolvers/jsResolver.js <—- Here my code is breaking up with error contains one or more error
TypeName: Query
FieldName: getInfo
Runtime:
Name: APPSYNC_JS
RuntimeVersion: 1.0.0
PipelineConfig:
Functions:
- !GetAtt AppSyncFunction.FunctionId
I have tried above code as per AWS Cloudformation documentation for Appsync available where they have mentioned that in AWS::AppSync::Resolver for creating Javascript Resolver using Cloudformation as below one of the properties. which I have included in my AWS::AppSync::Resolver
Code
The resolver code that contains the request and response functions. When code is
used, the runtime is required. The runtime value must be APPSYNC_JS.
Required: No
Type: String
Required: No
Type: String
So I've tried this and cant find enough solutions regarding Javascript Resolvers all are available with VTL template specific.
With above code my CloudFormation build failed with the following error: An error occurred: AppSyncJSResolver- The code contains one or more errors. (Service: AWSAppSync; Status Code: 400; Error Code: BadRequestException; Request ID: 0245d64d-...; Proxy: null)
AppSyncJSResolver- which is my AWS::AppSync::Resolver in above code. and I have code property in that which giving me an error. I have verified with multiple sources and I am not finding any errors with my Javascript Resolver file /src/resolvers/jsResolver.js which I have declared in AppSyncJSResolver AWS::AppSync::Resolver in code property, I am not sure why I’m getting this error, any help would be great.
To answering my own question, The way I resolve it via two ways.
1. We can write whole Resolver code in YML Cloudformation in Code property like below. Make sure your resolver code should be inside of your Code property and use "|" special character (Multi-line code) after Code property.
AppSyncJsResolver:
Type: AWS::AppSync::Resolver
Properties:
ApiId: !GettAtt Graphql.APiId
Kind: PIPELINE
Code: |
import { util } from '#aws-appsync/utils';
export function request(ctx) {
const {source, args} = ctx
return {
operation: 'Invoke',
payload: { field: ctx, arguments: args, source },
};
}
export function response(ctx) {
util.error("Failed to fetch relatedPosts", "LambdaFailure",ctx.prev.result)
return ctx.result;
}
TypeName: Query
FieldName: getInfo
Runtime:
Name: APPSYNC_JS
RuntimeVersion: 1.0.0
PipelineConfig:
Functions:
- !GetAtt AppSyncFunction.FunctionId
2. If you want to keep your business logic out of YML file and keep it separate then you can use CodeS3Location property in your javascript resolver like below.
first create bucket in S3 and store your javascript resolver file with your resolver code in bucket. make sure you give enough IAM permission to your appsync to access your S3 bucket.
After above step you can rewrite your YML Cloudformation like below
AppSyncJsResolver:
Type: AWS::AppSync::Resolver
Properties:
ApiId: !GettAtt Graphql.APiId
Kind: PIPELINE
CodeS3Location:s3://my-bucket-name/my-filename.js
TypeName: Query
FieldName: getInfo
Runtime:
Name: APPSYNC_JS
RuntimeVersion: 1.0.0
PipelineConfig:
Functions:
- !GetAtt AppSyncFunction.FunctionId
Hope this help others and will contribute more about Javascript Resolver so it will be easier for other to find more complex solutions and get as much as resources about Javascript Resolver. Thanks to #Graham Hesketh for your suggestions.

Blazor Azure Static Web App not executing Javascript

I'm using a little bit of Javascript in my Blazor app to do some light work. Everything works fine on my local computer. When I publish to my Azure Static Web App, the Javascript does not execute. Here is the error message.
Refused to execute script from 'https://fullUrl/js.download' because its MIME type ('application/octet-stream') is not executable, and strict MIME type checking is enabled.
Here is my yaml file.
trigger:
- main
pool:
vmImage: ubuntu-latest
# vmImage: windows-latest
steps:
- checkout: self
submodules: true
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
- task: AzureStaticWebApp#0
inputs:
app_location: '/'
api_location: ''
output_location: 'wwwroot'
azure_static_web_apps_api_token: $(deployment_token)
I placed this in my staticwebapp.config.json file.
"mimeTypes": {
".json": "text/json",
".js": "application/octet-stream"
}
Does anyone know how to get this to work? Thanks!
I finally got all of this to work. I renamed myfile.js.download to just myfile.js. I then changed another js file to js.js. Anyway, that seemed to be the change that was needed.
Here is the updated yaml file.
trigger:
- master
pool:
vmImage: ubuntu-latest
# vmImage: windows-latest
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: 'build'
arguments: '--configuration Release'
projects: 'YourProjectName.csproj'
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration Release'
zipAfterPublish: false
- task: AzureStaticWebApp#0
inputs:
skip_app_build: true
app_location: '/bin/Release/net5.0/publish/wwwroot'
output_location: ''
azure_static_web_apps_api_token: 'YOURDEPLOYMENTTOKEN'

Serverless: Creating S3Bucket and BucketPolicy [Unresolved resource dependencies]

I'm trying to create an S3 Bucket and a corresponding Resource Policy in the same serverless.yml so that both are established on the new stack formation.
However, I am running into an error on build:
Unresolved resource dependencies [CUSTOM-BUCKETNAME] in the Resources block of the template
Is there to a way to synchronously create the policy so that it waits for the bucket to be created first? I'm setting this up in the resources section of my yml
resources:
Resources:
Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: CUSTOM-BUCKETNAME
BucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket:
Ref: CUSTOM-BUCKETNAME
PolicyDocument:
Statement:
- Principal:
Service: "ses.amazonaws.com"
Action:
- s3:PutObject
Effect: Allow
Sid: "AllowSESPuts"
Resource:
Fn::Join: ['', ['arn:aws:s3:::', Ref: "CUSTOM-BUCKETNAME", '/*'] ]
Above is a small snippet of my yml configuration.
After using DependsOn, I'm still getting the same error. Worth note, the resource dependency refers to the dynamic name (CUSTOM-BUCKETNAME) of the bucket.
resources:
Resources:
Bucket:
Type: AWS::S3::Bucket
Properties:
BucketName: CUSTOM-BUCKETNAME
BucketPolicy:
Type: AWS::S3::BucketPolicy
DependsOn: Bucket
Properties:
Bucket:
Ref: CUSTOM-BUCKETNAME
PolicyDocument:
Statement:
- Principal:
Service: "ses.amazonaws.com"
Action:
- s3:PutObject
Effect: Allow
Sid: "AllowSESPuts"
Resource:
Fn::Join: ['', ['arn:aws:s3:::', Ref: "CUSTOM-BUCKETNAME", '/*'] ]
CUSTOM-BUCKETNAME is never explicity hardcoded in the yml itself, its a dynamically generated name using template literals.
Issue is occurring on your policy as your bucket is: BucketName: CUSTOM-BUCKETNAME
Not a referenced parameter. Which means your not referencing the actual resource in the policy statement when your using Bucket: Ref: CUSTOM-BUCKETNAME.
Instead, either change the bucket name to reference the same parameter BucketName: Ref: CUSTOM-BUCKETNAME or change the policy to reference the resource: Bucket: Ref: Bucket
CloudFormation DependsOn attribute should solve your problem.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html

Swagger error :ptr must be a JSON Pointer

I am trying to run my swagger file and i keep getting this error.
Error: ptr must be a JSON Pointer
at pathFromPtr (/Users/salma/Desktop/swaggerIntegration/node_modules/json-refs/index.js:1128:11)
at /Users/salma/Desktop/swaggerIntegration/node_modules/json-refs/index.js:293:45
at process.runNextTicks [as _tickCallback] (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:800:11)
at executeUserCode (internal/bootstrap/node.js:526:15)
at startMainThreadExecution (internal/bootstrap/node.js:439:3)
and here is my swagger file
swagger: "2.0"
info:
version: "0.0.1"
title: employees DB
# during dev, should point to your local machine
host: localhost:10010
# basePath prefixes all resource paths
basePath: /
#
schemes:
# tip: remove http to make production-grade
- http
- https
# format of bodies a client can send (Content-Type)
consumes:
- application/json
# format of the responses to the client (Accepts)
produces:
- application/json
paths:
/employees:
# binds a127 app logic to a route
x-swagger-router-controller: employees
get:
description: Returns 'Hello' to the caller
# used as the method name of the controller
operationId: index
parameters:
- name: name
in: query
description: The name of the person to whom to say hello
required: false
type: string
responses:
"200":
description: Success
schema:
# a pointer to a definition
$ref: "#/definitions/employeesListBody"
# responses may fall through to errors
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
/swagger:
x-swagger-pipe: swagger_raw
# complex objects have schema definitions
definitions:
employeesListBody:
required:
- employees
properties:
employees:
type: array
items:
$ref: "#definitions/Employee"
Employee:
required:
- name
- email
- position
properties:
name:
type: string
email:
type: string
position:
type: string
age:
type: integer
minimum: 20
ErrorResponse:
required:
- message
properties:
message:
type: string
any idea how to solve that ?
is there an easier way to prettify the swagger file? because i get many parsing erros.
also does any one have a good example of using swagger with express and mongodb ?
many thanks.
One of the references is missing a / after #:
$ref: "#definitions/Employee"
Change it to:
$ref: "#/definitions/Employee"
# ^
If you paste your definition into http://editor.swagger.io, it shows where exactly the error is.

Is it possible to autogenerate Swagger yaml from the routes available in Node.js?

REST Api services is available in Node.js express app along with routes are specified properly. I am planning to use node.js to auto generate the swagger YAML Open API specification. Writing a swagger YAML manually is tough if you have more endpoints and the intention to add more endpoints will need to update everywhere.
Example: Consider a REST API services contains two basic endpoints and specified in the following YAML
swagger: "2.0"
info:
version: "0.0.1"
title: Hello World App
# during dev, should point to your local machine
host: localhost:10010
# basePath prefixes all resource paths
basePath: /
#
schemes:
# tip: remove http to make production-grade
- http
- https
# format of bodies a client can send (Content-Type)
consumes:
- application/json
# format of the responses to the client (Accepts)
produces:
- application/json
paths:
/hello:
# binds a127 app logic to a route
x-swagger-router-controller: hello_world
get:
description: Returns 'Hello' to the caller
# used as the method name of the controller
operationId: hello
parameters:
- name: name
in: query
description: The name of the person to whom to say hello
required: false
type: string
responses:
"200":
description: Success
schema:
# a pointer to a definition
$ref: "#/definitions/HelloWorldResponse"
# responses may fall through to errors
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
/try:
x-swagger-router-controller: hello_world
get:
description: Returns 'Try' to the caller
operationId: try
parameters:
- name: name
in: query
description: The content to try
required: false
type: string
responses:
"200":
description: Success
schema:
$ref: "#/definitions/HelloWorldResponse"
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
/swagger:
x-swagger-pipe: swagger_raw
# complex objects have schema definitions
definitions:
HelloWorldResponse:
required:
- message
properties:
message:
type: string
ErrorResponse:
required:
- message
properties:
message:
type: string
My doubt is how can i generate this YAML in Node.js? Is there any specific NPM package or any swagger module available to generate this kind of YAML or writing code on own is preferable?
Trying to analyze the better way to do this. I appreciate all suggestions and thanks in advance!

Categories