aws / aws-tools-for-powershell

The AWS Tools for PowerShell lets developers and administrators manage their AWS services from the PowerShell scripting environment.
Apache License 2.0
238 stars 79 forks source link

The file is empty. Empty files cannot be added to a repository. #54

Closed jda2004 closed 4 years ago

jda2004 commented 4 years ago

Write-CCFile -RepositoryName test-repo -BranchName master -FilePath /test/tst.tst -ParentCommitId abc123test -ProfileName test-profile

Write-CCFile : The file is empty. Empty files cannot be added to a repository.

I am continuously getting this error message even though the file is not empty. The goal is to write a file in codecommit using this syntax.

matteo-prosperi commented 4 years ago

Hello, I think you are missing the -FileContent parameter

jda2004 commented 4 years ago

What do i put in -FileContent, the content of the file? I have a create table DDL in this file. Sould I just copy and paste that content within a single qoute?

matteo-prosperi commented 4 years ago

I think the simplest way to do this is

-FileContent ([System.IO.File]::ReadAllBytes('path to my file'))

-FilePath is the relative path to the file in the repository, not the path to a local file.

I am not familiar with these CodeCommit APIs but, if I read the docs correctly, this API will create one new commit for each file you add. In case you want to add multiple files in the same commit, New-CCCommit should do that.

jda2004 commented 4 years ago

And............... it worked!!!.... thank you @matteo-prosperi You solved my 4 hours of digging in one shot!!!

jda2004 commented 4 years ago

Hi @matteo-prosperi : I like to add little more information in my script. So this is the original syntax pattern from aws Write-CCFile -RepositoryName -BranchName -CommitMessage -Email -FileContent <Byte[]> -FileMode -FilePath -Name -ParentCommitId -Force I was thinking what content to go in FileMode and how to use '-Force' to force commit? Is the '-Name' going to be the destination file name?

matteo-prosperi commented 4 years ago

Hi, I can tell you that -Force is simply the PowerShell common parameter which will bypass the confirmation prompt of this cmdlet. -Force doesn't have any CodeCommit-specific use.

When it comes to the other parameters, have a look at the reference docs here. -Name appears to be "the name of the person adding or updating the file". -FileMode is one of the values of the FileModeTypeEnum (so you can do -FileMode NORMAL).

jda2004 commented 4 years ago

One more :) @matteo-prosperi I am now thinking to put this syntax in an automation tool (WhereScape Red) template that will write the generated load script directly into the codecommit. In this case, I need to enable the FileContent to read a variable string. How to do that? For example: -FileContent ([System.IO.File]::ReadAllBytes('$Loadsql'))

matteo-prosperi commented 4 years ago

I am not sure I understand whether you have the file name in a variable or the content of the file in a variable. The former would be

-FileContent ([System.IO.File]::ReadAllBytes($FilePath))

the latter

-FileContent ([System.Text.Encoding]::UTF8.GetBytes($SomeText))
jda2004 commented 4 years ago

Sorry for the confusion on the question, but you answered it with 'the latter' one. And it's working. Thanks for developing this one.