Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
Add AWS CodePipeline event definition
Browse files Browse the repository at this point in the history
CAT: #feat #doc
REF: #1
  • Loading branch information
fsenart committed Mar 4, 2017
1 parent ff41a7c commit a318481
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ go get -u -d github.com/eawsy/aws-lambda-go-event/...
- [Amazon Simple Email Service Events][eawsy-sesevt]
- [Amazon Simple Notification Service Events][eawsy-snsevt]
- [AWS CloudFormation Events][eawsy-cloudformationevt]
- [AWS CodePipeline Events][eawsy-codepipelineevt]

[<img src="_asset/misc_arrow-up.png" align="right">](#top)
## About
Expand Down Expand Up @@ -121,6 +122,7 @@ affiliates in the United States and/or other countries.
[eawsy-sesevt]: /service/lambda/runtime/event/sesevt
[eawsy-snsevt]: /service/lambda/runtime/event/snsevt
[eawsy-cloudformationevt]: /service/lambda/runtime/event/cloudformationevt
[eawsy-codepipelineevt]: /service/lambda/runtime/event/codepipelineevt

[aws-home]: https://aws.amazon.com/
[aws-lambda-home]: https://aws.amazon.com/lambda/
Expand Down
56 changes: 56 additions & 0 deletions service/lambda/runtime/event/codepipelineevt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<a id="top" name="top"></a>

# AWS CodePipeline Events

[<img src="/_asset/misc_home.png" alt="Back to Home" align="right">](/)
[![Go Doc][badge-doc-go]][eawsy-doc]
[![AWS Doc][badge-doc-aws]][aws-doc]

This package allows to write AWS Lambda functions and add them as action in your pipelines to customize the way they
work.

[<img src="/_asset/misc_arrow-up.png" align="right">](#top)
## Quick Hands-On

> For step by step instructions on how to author your AWS Lambda function code in Go, see
[eawsy/aws-lambda-go-shim][eawsy-runtime].

```sh
go get -u -d github.com/eawsy/aws-lambda-go-event/...
```

```go
package main

import (
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codepipeline"
"github.com/eawsy/aws-lambda-go-core/service/lambda/runtime"
"github.com/eawsy/aws-lambda-go-event/service/lambda/runtime/event/codepipelineevt"
)

func Handle(evt *codepipelineevt.Event, ctx *runtime.Context) (interface{}, error) {
log.Println(evt)
sess, err := session.NewSession()
if err != nil {
return nil, err
}
svc := codepipeline.New(sess)
_, err = svc.PutJobSuccessResult(&codepipeline.PutJobSuccessResultInput{
JobId: aws.String(evt.Job.ID),
})
return nil, err
}
```

[eawsy-runtime]: https://github.com/eawsy/aws-lambda-go-shim
[eawsy-doc]: https://godoc.org/github.com/eawsy/aws-lambda-go-event/service/lambda/runtime/event/codepipelineevt

[aws-doc]: http://docs.aws.amazon.com/codepipeline/latest/userguide/welcome.html

[badge-doc-go]: http://img.shields.io/badge/api-godoc-3F51B5.svg?style=flat-square
[badge-doc-aws]: http://img.shields.io/badge/api-awsdoc-FF9800.svg?style=flat-square

30 changes: 30 additions & 0 deletions service/lambda/runtime/event/codepipelineevt/decoder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Copyright 2017 Alsanium, SAS. or its affiliates. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package codepipelineevt

import "encoding/json"

// UnmarshalJSON interprets data as map in order to extract the incoming
// "CodePipeline.job" key and make the Event struct json-tag-less.
func (e *Event) UnmarshalJSON(data []byte) error {
var t map[string]*Job
if err := json.Unmarshal(data, &t); err != nil {
return err
}
e.Job = t["CodePipeline.job"]
return nil
}
136 changes: 136 additions & 0 deletions service/lambda/runtime/event/codepipelineevt/definition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//
// Copyright 2017 Alsanium, SAS. or its affiliates. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package codepipelineevt

import "encoding/json"

// AWSSessionCredentials represents an AWS session credentials object.
// These credentials are temporary credentials that are issued by AWS Secure
// Token Service (STS). They can be used to access input and output artifacts in
// the Amazon S3 bucket used to store artifact for the pipeline in AWS
// CodePipeline.
type AWSSessionCredentials struct {
// The access key for the session.
AccessKeyID string

// The secret access key for the session.
SecretAccessKey string

// The token for the session.
SessionToken string
}

// ActionConfiguration represents information about an action configuration.
type ActionConfiguration struct {
// The configuration data for the action.
Configuration *struct {
// AWS Lambda function name.
FunctionName string

// An arbitrary string of user formatted configuration for the
// AWS Lambda function to complete the job.
UserParameters string
}
}

// S3ArtifactLocation represents the location of the Amazon S3 bucket that
// contains a revision.
type S3ArtifactLocation struct {
// The name of the Amazon S3 bucket.
BucketName string

// The key of the object in the Amazon S3 bucket, which uniquely
// identifies the object in the bucket.
ObjectKey string
}

// ArtifactLocation represents information about the location of an artifact.
type ArtifactLocation struct {
// The type of artifact in the location.
Type string

// The Amazon S3 bucket that contains the artifact.
S3Location *S3ArtifactLocation
}

// Artifact represents information about an artifact that will be worked upon
// by actions in the pipeline.
type Artifact struct {
// The artifact's name.
Name string

// The artifact's revision ID.
// Depending on the type of object, this could be a commit ID (GitHub)
// or a revision ID (Amazon S3).
Revision string

// The location of an artifact.
Location *ArtifactLocation
}

// Data represents additional information about an AWS CodePipeline job required
// for the AWS Lambda function to complete the job.
type Data struct {
// Information about an action configuration.
ActionConfiguration *ActionConfiguration

// A system-generated token, such as an AWS CodeDeploy deployment ID,
// that a job requires in order to continue the job asynchronously.
ContinuationToken string

// An AWS session credentials object.
// These credentials are temporary credentials that are issued by AWS
// Secure Token Service (STS). They can be used to access input and
// output artifacts in the Amazon S3 bucket used to store artifact for
// the pipeline in AWS CodePipeline.
ArtifactCredentials *AWSSessionCredentials

// The artifact supplied to the job.
InputArtifacts []*Artifact

// The output of the job.
OutputArtifacts []*Artifact
}

// Job represents information about the details of an AWS CodePipeline job.
type Job struct {
// The unique system-generated ID of the job.
ID string

// The ID of the AWS account to use when performing the job.
AccountID string

// Additional information about the job.
Data *Data
}

// Event represents an AWS CodePipeline event.
type Event struct {
// Information about the details of the job.
Job *Job
}

// String returns the string representation.
func (e *Event) String() string {
s, _ := json.Marshal(e)
return string(s)
}

// GoString returns the string representation.
func (e *Event) GoString() string {
return e.String()
}
21 changes: 21 additions & 0 deletions service/lambda/runtime/event/codepipelineevt/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright 2017 Alsanium, SAS. or its affiliates. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

/*
Package codepipelineevt allows you to write AWS Lambda functions and add them as
action in your pipelines to customize the way they work.
*/
package codepipelineevt

0 comments on commit a318481

Please sign in to comment.